本人使用java做后台,后台使用同一公钥文件(格式为ANS.1 DER编码方式 长度为2048模长 ),加密111111(NO_PADDING)字符串得到结果 A55F50..... 开头的16进制编码,但是在ios平台使用openssl和同一公钥文件加密111111始终得不到A55F50开头的结果,代码如下,请大神帮忙看看....
#define MODULUS "CF4D10C2C011FCF1EE8F660C9B8AD7E7C8BAAB285C8168F2B355145CCFEAE4E555AC1C4926B00FFF23EC49800B159040F05BA1CC25F4D997311048292904B4015E5A419C0CFE21CC08B144575CC65BD05D5B36EECC190592BD66DACA68B49A3B0D2B1ACE4D26F50339DB834004FAABF399BD66296CA85C8F3E840E1864036A2CDDBDC5188CCF6C23928AA699C3564DB1F83561501A2C8033A34516161DF27B9C8357041291B39203C53E87027F2024A07F3DEBD41FB286CEB4824659347BF2863A6688497E56BFE4B417992F026719D2A199EC6481983636D10FBF74B8011EE5A8D27EAFE7A8E7B33FFED35167783B5753C74C2EBA7C36D134F1090EACEBC225"
#define PUBLIC_EXPONENT 65537
int ret, flen;
BIGNUM *bnn, *bne,*bnd;
bnn = BN_new();
bne = BN_new();
//bnd = BN_new();
BN_hex2bn(&bnn, MODULUS);
BN_set_word(bne, PUBLIC_EXPONENT);
//BN_hex2bn(&bnd, MODULUS);
RSA *r = RSA_new();
//RSA* r = RSA_generate_key( 2048 ,RSA_F4,0,0);
r->e = bne;
r->n = bnn;
//r->d = bnd;
RSA_print_fp(stdout, r, 5);
flen = RSA_size(r);// - 11;
/*out = (char *)malloc(flen);
bzero(out, flen);*/
//memset(out, 0, flen);
char *sp = (char *)malloc(flen);
bzero(sp, flen);
//memset(sp, 0, flen);
char *message = "111111";
BIGNUM *rs;
rs = BN_new();
ret = RSA_public_encrypt(flen, (unsigned char *)message , (unsigned char *)sp, r, RSA_NO_PADDING);
if (ret > 0)
{
//BN_bin2bn((unsigned char *)sp, flen, rs);
//NSLog(@"Encrypt OK, sp=%s",BN_bn2hex(rs));//转为16进制
unsigned char *tmpData;
tmpData=(unsigned char *)sp;
for (int i=0; i<ret; i++){
printf("%02X", *tmpData);
tmpData++;
}
//BN_bin2bn((unsigned char *)sp, flen, rs);
//NSLog(@"Encrypt OK, sp=%s",BN_bn2hex(rs));//转为16进制
}
RSA_free(r);