#include #include #include #include // error #include // AES-256 加密示例 void aes256_encrypt(const unsigned char* plaintext, size_t plaintext_len, const unsigned char key[AES_BLOCK_SIZE], unsigned char iv[AES_BLOCK_SIZE], unsigned char* ciphertext) { AES_KEY aes; // 初始化加密密钥 if (AES_set_encrypt_key(key, 256, &aes) < 0) { // 错误处理:密钥长度不正确等 } // 创建一个用于CBC模式的加密上下文结构体 AES_cbc_encrypt(plaintext, ciphertext, plaintext_len, &aes, iv, AES_ENCRYPT); } int main() { unsigned char plaintext[AES_BLOCK_SIZE] = { /* 填充原始数据 */ }; unsigned char key[AES_BLOCK_SIZE] = { /* 填充密钥 */ }; unsigned char iv[AES_BLOCK_SIZE] = { /* 填充初始化向量(IV) */ }; unsigned char ciphertext[AES_BLOCK_SIZE]; aes256_encrypt(plaintext, sizeof(plaintext), key, iv, ciphertext); // ... 然后可以进一步处理密文 ... return 0; }