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_PKCS1_PADDING这个不就代表填充了吗
怎么解决啊,大哥
@life清者自清: 填充好像是有区别的.不知道你这个方法的用法.你查下API文档吧.
@吴瑞祥: ...就三种
https://q.cnblogs.com/q/87207/