我想使用openssl使用AES 128對數據進行加密/解密。使用openssl進行數據加密/ ecryption
void main(void)
{
unsigned char key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
AES_KEY enc_key, dec_Key;
unsigned char text = "Data encryption/ecryption with openssl";
unsigned char encrtext[64], decrptext[64];
AES_set_encrypt_key(key, 128, &enc_Key);
AES_encrypt(text, encrtext, &enc_Key);
AES_set_decrypt_key(key,128,&dec_key);
AES_decrypt(encrtext, decrptext, &dec_Key);
printf("Data = %s",decrptext);
}
此程序的執行使
Data = Data encryption/
我看到,只有16個字符被加密和解密。你能幫忙解決這個問題嗎? 謝謝
[如何在OpenSSL中使用AES進行加密](http://stackoverflow.com/questions/9889492/how-to-do-encryption-using-aes-in-openssl) – jww
您應該*不*使用'AES_encrypt'和朋友。您應該使用'EVP_ *'功能。請參閱OpenSSL wiki上的[EVP Symmetric Encryption and Decryption](https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption)。事實上,您應該使用經過身份驗證的加密,因爲它提供了*機密性和真實性。請參閱OpenSSL wiki上的[EVP Authenticated Encryption and Decryption](https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption)。 – jww