php和c上的OpenSSL提供不同的编码数据。为什么不同的编码结果? 如何纠正与CBC-256-ivec同步php和c模式?不要在php模式和c模式下看到任何不同。
(每个解密返回正确的传入字符串)
1.Php简单代码是:
$s = 'key12345';
$v = '1234567812345678';
$c="HEllo111111111111111111999999999911111111111111111111Hello";
$d=openssl_encrypt($c,'aes-256-cbc',$s,1,$v);// options OPENSSL_RAW_DATA=1
echo bin2hex($d);
以十六进制表示的第一个编码字节为:e1 a9 52 4f 78 2b a8 41 b4 fe 2d 49 8d
2.C简单代码是:
AES_KEY aeskey;
char *simplekey = "key12345";
int status = AES_set_encrypt_key((unsigned char*) simplekey, 256, &aeskey);
unsigned char ivec[] = "1234567812345678";
unsigned char messagein[] = "HEllo111111111111111111999999999911111111111111111111Hello";
unsigned char * msg_enc_out = (unsigned char *)malloc(80);
memset(msg_enc_out, 0, 80);
AES_cbc_encrypt((unsigned char *) messagein, msg_enc_out, sizeof(messagein), &aeskey, ivec, AES_ENCRYPT);
printf("\nencrypted:\n");
printf("lenght=%d\n", sizeof(msg_enc_out));
for(i=0;*(msg_enc_out+i)!=0x00;i++)
printf("%X ",*(msg_enc_out+i));
以十六进制表示的第一个编码字节为:C4 E8 19 30 98 5A 52 6 C7 9F 49 6D DE