首页 新闻 赞助 找找看

加密后密文长度有时等于公钥长度128,有时候不等于,什么原因啊,加密代码如下:

0
悬赏园豆:50 [已关闭问题] 关闭于 2016-10-17 19:04

char my_encrypt(char str, char *pubkey_path)
{
// 打开公钥文件
FILE pub_fp=fopen(PUBKEY,"r");
if(pub_fp==NULL){
printf("failed to open PUBKEY file %s!\n", PUBKEY);
return ;
}
// 从文件中读取公钥
RSA
 rsa1=PEM_read_RSA_PUBKEY(pub_fp, NULL, NULL, NULL);
if(rsa1==NULL)
{
printf("unable to read public key!\n");
return ; 
}
fclose(pub_fp);
printf("strlen(str): %d\n",strlen(str));
printf("RSA_size(rsa1): %d\n",RSA_size(rsa1));

char *encrypted=NULL;
encrypted = (char *)malloc(1024);
memset(encrypted, 0, 1024);
// 用公钥加密
int len=RSA_public_encrypt(strlen(str), str, encrypted, rsa1, RSA_PKCS1_PADDING);
if(len==-1 )
{
printf("failed to encrypt\n");
return ;
}
return encrypted;
}

RSA
life清者自清的主页 life清者自清 | 初学一级 | 园豆:76
提问于:2016-10-17 17:32
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册