这些问题通常是由于加密和解密时使用的初始向量(IV)不同导致的。在使用MODE_CFB AES模式进行加密和解密时,请确保使用相同的IV。下面是一个C++示例,演示如何使用MODE_CFB进行加密和解密,并确保使用相同的IV:
#include
#include
int main() {
const unsigned char key[] = "0123456789123456";
const unsigned char iv[] = "0123456789123456";
const unsigned char plaintext[] = "This is a secret message";
const int plaintext_len = strlen((char*)plaintext);
unsigned char ciphertext[plaintext_len];
unsigned char decrypted_text[plaintext_len];
AES_KEY aes_key;
AES_set_encrypt_key(key, 128, &aes_key);
AES_cfb128_encrypt(plaintext, ciphertext, plaintext_len, &aes_key, iv, NULL, AES_ENCRYPT);
AES_set_decrypt_key(key, 128, &aes_key);
AES_cfb128_decrypt(ciphertext, decrypted_text, plaintext_len, &aes_key, iv, NULL, AES_DECRYPT);
std::cout << decrypted_text << std::endl;
return 0;
}