信息安全课程设计_信息安全课程设计报告

2020-02-27 其他范文 下载本文

信息安全课程设计由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“信息安全课程设计报告”。

信息系统安全课程设计报告

课题名称:OpenSSL 非对称加密

提交文档学生姓名:提交文档学生学号:

同组 成 员 名 单:指导 教 师 姓 名:

指导教师评阅成绩:指导教师评阅意见:

提交报告时间: 2014年 6 月 10日

1.课程设计目标

了解OpenSSL非对称加密算法的背景知识,并实现加密解密。

2.分析与设计

(1)实现方法:

编程语言为C++语言。

编程方法:根据算法要求编写代码。

(2)利用OpenSSL命令制作生成密钥:

#include

#include

#include

#include

#include

int main()

{

char plain[256]=“啦啦啦啦啦”;

char encrypted[1024];

char decrypted[1024];

const char* pub_key=“public.pem”;

const char* priv_key=“private.pem”;

printf(“%sn”,plain);int len=strlen(plain);BIO *pBio = BIO_new_file(pub_key,“r”);if(pBio==NULL){

printf(“failed to open pub_key file %s!n”, pub_key);

return-1;

}

RSA* rsa1= PEM_read_bio_RSA_PUBKEY(pBio, NULL, NULL, NULL);

if(rsa1==NULL){

printf(“unable to read public key!n”);

return-1;

}

BIO_free_all(pBio);int outlen=RSA_public_encrypt(len,(unsigned char *)plain,(unsigned char *)encrypted, rsa1,RSA_PKCS1_PADDING);

printf(“%dn”,outlen);encrypted[outlen]='';printf(“%sn”,encrypted);FILE* fp=fopen(“out.txt”,“w”);fwrite(encrypted,1,outlen,fp);fclose(fp);pBio = BIO_new_file(priv_key,“r”);if(pBio==NULL){

printf(“failed to open priv_key file %s!n”, pub_key);

return-1;

}

RSA *rsa2 = PEM_read_bio_RSAPrivateKey(pBio, NULL, NULL, NULL);

if(rsa2==NULL){

printf(“unable to read private key!n”);

return-1;

}

BIO_free_all(pBio);

outlen=RSA_private_decrypt(outlen,(unsigned char *)encrypted,(unsigned char *)decrypted, rsa2,RSA_PKCS1_PADDING);

}

(3)手动产生公钥:

#include

#include

#include

#include

#include

int main()

{

char plain[256]=“rtre”;

char encrypted[1024];

decrypted[outlen]='';printf(“%sn”,decrypted);return 0;

char decrypted[1024];

const char* pub_key=“public2.pem”;

const char* priv_key=“private2.pem”;

const int g_nBits = 1024;

printf(“%sn”,plain);

int len=strlen(plain);RSA *rsa1 = RSA_generate_key(g_nBits,RSA_F4,NULL,NULL);

if(rsa1 == NULL)

{

printf(“rsa_generate_key errorn”);

return-1;

}

BIO *pBio = BIO_new_file(pub_key,“w”);

if(pBio == NULL)

{

printf(“BIO_new_file %s errorn”, pub_key);

return-1;

}

PEM_write_bio_RSAPublicKey(pBio,rsa1);

BIO_free_all(pBio);

int outlen=RSA_public_encrypt(len,(unsigned char *)plain,(unsigned char *)encrypted, rsa1,RSA_PKCS1_PADDING);

printf(“%dn”,outlen);

encrypted[outlen]='';

printf(“%sn”,encrypted);

FILE* fp=fopen(“out.txt”,“w”);

fwrite(encrypted,1,outlen,fp);

fclose(fp);

pBio = BIO_new_file(priv_key,“w”);

if(pBio == NULL)

{

printf(“BIO_new_file %s errorn”, priv_key);

return-1;

}

PEM_write_bio_RSAPrivateKey(pBio,rsa1,NULL,NULL,NULL,NULL,NULL);BIO_free_all(pBio);outlen=RSA_private_decrypt(outlen,(unsigned char *)encrypted,(unsigned char *)decrypted, rsa1,RSA_PKCS1_PADDING);

decrypted[outlen]='';

printf(“%sn”,decrypted);

return 0;

}

3.总结

RSA是目前最有影响力的公钥加密算法,它能够抵抗到目前为止已知的绝大多数密码攻击,已被ISO推荐为公钥数据加密标准,学习这个算法让我对加密和解密的知识有了更加深入的理解。同时也提高了我的编程能力。每次实现一个算法,都让我对信息安全相关的技术更加有兴趣,原本枯燥的学习变得非常生动有趣。

感谢老师的耐心指导,这门课真的很有意思,老师讲得也很好,让我受益匪浅。

《信息安全课程设计.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
信息安全课程设计
点击下载文档
相关专题 信息安全课程设计报告 信息安全 课程设计 信息安全课程设计报告 信息安全 课程设计
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文