2
我在JAVA
中做了AES/ECB/PKCS5Padding
加密。現在我正在尋找C/C++
中的等效方法。我並管理使用以下代碼用C來加密:在C/C++中用於AES加密的PKCS#5填充
const unsigned char *key = (unsigned char *)"A2XTXFEQFOPZFAKXFOPZFAK5";
unsigned char input[] = {"Hello World"};
int iLen = strlen((char*)input);
int len = 0;
if(iLen % 16 == 0){
len = iLen;
}
else{
len = (iLen/16)*16 + 16;
}
unsigned char output[len]; //next 16bit
AES_KEY enc_key;
AES_set_encrypt_key(key, strlen((char*)key)*8, &enc_key);
int position = 0;
while(position < iLen){
AES_ecb_encrypt(input+position,output+position,&enc_key,AES_ENCRYPT);
position += 16;
}