无法使用openssl为es gcm设置IV [英] Unable to set IV for aes gcm using openssl

查看:256
本文介绍了无法使用openssl为es gcm设置IV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C ++中OpenSSL提供的AES GCM加密机制,并在此链接上使用示例作为参考:
https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption

I am trying to use AES GCM encryption mechanism provided by OpenSSL in C++ and using example on this link as reference: https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption

但是,以下语句给我错误:

However, following statement gives me error:

/* 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。

error: ‘EVP_CTRL_GCM_SET_IVLEN’ was not declared in this scope".

我不明白,为什么我不能将IVLEN设置为16个字节吗?我不想
使用默认值12个字节。任何指针都很好。

I do not understand, why I cannot set IVLEN to 16 bytes? I do not want to use the default value of 12 bytes. Any pointers will be great.

推荐答案

我解决了这个错误,实际上,在示例代码中,初始化加密操作和设置IV长度的顺序如下:

I resolved the error. Actually, in the example code, the order for initializing encryption operation and setting IV length is as follows:

* 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长度然后再初始化加密操作。我以为,这些是独立的步骤,顺序无关紧要。但是,也许接口需要在设置任何参数之前知道使用了哪种加密机制。

I had reverse order for these statements i.e. setting IV length first and then initializing encryption operation. I thought, these were independent steps and the order didn't matter. But, maybe, the interface needs to know, which encryption mechanism it has use before setting any parameters.

这篇关于无法使用openssl为es gcm设置IV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆