无法使用openssl为aes gcm设置IV
Unable to set IV for aes gcm using openssl
我正在尝试使用OpenSSL在c++中提供的AES GCM加密机制,并在此链接上使用示例作为参考:https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption
但是,下面的语句给了我错误:
/* Set IV length if default 12 bytes (96 bits) is not appropriate */
if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL))
handleErrors();
我得到的错误是:
错误:' EVP_CTRL_GCM_SET_IVLEN '未在此范围内声明'。
我不明白,为什么我不能将IVLEN设置为16字节?我不想使用默认值12字节。
我解决了这个错误。实际上,在示例代码中,初始化加密操作和设置IV长度的顺序如下:
* Initialise the encryption operation. */
if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL))
handleErrors();
/* Set IV length if default 12 bytes (96 bits) is not appropriate */
if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL))
handleErrors();
我对这些语句有相反的顺序,即先设置IV长度,然后初始化加密操作。我想,这些是独立的步骤,顺序无关紧要。但是,在设置任何参数之前,接口可能需要知道它使用了哪种加密机制。
相关文章:
- AES加密到解密未正确输出
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- OpenSSL API,使用GCM(伽罗瓦计数器模式)进行AES加密
- 压缩天然气.AES.错误解密(可能加密)的文件
- 用于 AES-gcm 加密的 IV 中是否有不起作用的值?
- OpenSSL AES加密似乎无法正常工作
- AES ECB已知文本攻击
- AES-128 CFB-8解密的前16个字节已损坏
- C++中AES NI加密的正确方法
- aes cbc反向加密
- 在Crypto++中向AES解密传递密钥
- 如何使用 AES 和 sha256 哈希作为密钥加密++进行加密
- 无法为 AES 加密创建 contex.视窗XP
- 短消息 AES 性能C++
- QT:AES-256-CBC 根据 PHP 代码在C++中加密/解密
- 在加密++中使用RSA加密对称AES密钥
- 错误:AES 加密密钥:从"char*"到"无符号字符"的转换无效
- AES GCM/CTR 相同的输出
- 无法使用openssl为aes gcm设置IV
- 在OS X上的Xcode中使用AES/GCM时编译错误