用openssl写入指定rsa密钥,能加密,不能解密,晕?
我用RSA_generate_key能通过,为什么我写如我的密钥又不能通过呢(我的密钥用RSA_check_key是能通过的)unsignedcharE[4]={0x00...
我用RSA_generate_key能通过,为什么我写如我的密钥又不能通过呢(我的密钥用RSA_check_key是能通过的)
unsigned char E[4]={
0x00,0x01,0x00,0x01
};
RSA *rsa1;
rsa1=RSA_new();
rsa1->n=BN_bin2bn(D,sizeof(D),rsa1->n);
rsa1->e=BN_bin2bn(E,sizeof(E),rsa1->e);
rsa1->d=BN_bin2bn(D,sizeof(D),rsa1->d);
rsa1->p=BN_bin2bn(P,sizeof(P),rsa1->p);
rsa1->q=BN_bin2bn(Q,sizeof(Q),rsa1->q);
rsa1->dmp1=BN_bin2bn(DP,sizeof(DP),rsa1->dmp1);
rsa1->dmq1=BN_bin2bn(DQ,sizeof(DQ),rsa1->dmq1);
rsa1->iqmp=BN_bin2bn(InverseQ,sizeof(InverseQ),rsa1->iqmp);
unsigned char buff[]={"wo shi lianghao."};
unsigned char buff1[128];
unsigned char buff2[128];
int ret;
ret=RSA_check_key(rsa1);//返回值正确
ret=RSA_public_encrypt(sizeof(buff),buff,buff1,rsa1,RSA_PKCS1_PADDING);//返回值正确
ret=RSA_private_decrypt(sizeof(buff1),buff1,buff2,rsa1,RSA_PKCS1_PADDING);//解密的时候就错了,怎么回事? 展开
unsigned char E[4]={
0x00,0x01,0x00,0x01
};
RSA *rsa1;
rsa1=RSA_new();
rsa1->n=BN_bin2bn(D,sizeof(D),rsa1->n);
rsa1->e=BN_bin2bn(E,sizeof(E),rsa1->e);
rsa1->d=BN_bin2bn(D,sizeof(D),rsa1->d);
rsa1->p=BN_bin2bn(P,sizeof(P),rsa1->p);
rsa1->q=BN_bin2bn(Q,sizeof(Q),rsa1->q);
rsa1->dmp1=BN_bin2bn(DP,sizeof(DP),rsa1->dmp1);
rsa1->dmq1=BN_bin2bn(DQ,sizeof(DQ),rsa1->dmq1);
rsa1->iqmp=BN_bin2bn(InverseQ,sizeof(InverseQ),rsa1->iqmp);
unsigned char buff[]={"wo shi lianghao."};
unsigned char buff1[128];
unsigned char buff2[128];
int ret;
ret=RSA_check_key(rsa1);//返回值正确
ret=RSA_public_encrypt(sizeof(buff),buff,buff1,rsa1,RSA_PKCS1_PADDING);//返回值正确
ret=RSA_private_decrypt(sizeof(buff1),buff1,buff2,rsa1,RSA_PKCS1_PADDING);//解密的时候就错了,怎么回事? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询