AES加密16字节无填充 [英] AES encryption of 16 bytes without padding
问题描述
这应该是一个简单的问题,但我找不到任何例子,或者找出openssl文件的答案。
This should be a simple question, but I can't find any examples or figure out the answer from the openssl docs.
我想加密正确 128位,这应该适合一个加密块。
I want to encrypt exactly 128 bits, which should fit in one encryption block.
所以我调用 EVP_EncyptInit_ex
,那么什么?
So I call EVP_EncyptInit_ex
, and then what?
我是否调用 EVP_EncryptUpdate_ex
(加密128位块)和 EVP_EncryptFinal_ex
(即使没有什么更多的加密)?
Do I call EVP_EncryptUpdate_ex
(to encrypt the 128 bit block) and EVP_EncryptFinal_ex
(even though there is nothing more left to encrypt)?
或只有 EVP_EncryptUpdate_ex
?
或只有 EVP_EncryptFinal_ex
?
推荐答案
已经弄清楚了这些步骤。
所以,这将是
Here, you have already figured out the steps. So, it will be
- EVP_encryptInit_ex
- EVP_EncryptUpdate_ex
- EVP_EncryptFinal_ex
EVP_EncryptFinal_ex
还照顾了数据不是块长度的倍数。
EVP_EncryptFinal_ex
also take care of the fact that data is not in multiple of block lengths.
在我看来,如果您只使用无填充的AES(EVP_接口负责填充),那么请继续 AES_encrypt
。
In my opinion, if you have only to use AES with no padding (EVP_ interfaces takes care of padding), then go for AES_encrypt
.
它们相当容易使用。
//Step 1: Set encrypt key.
AES_KEY aeskey;
AES_set_encrypt_key(key, bits, &aeskey);
//Step2: Encrypt exactly 128 bits.
AES_encrypt(data, dataout, &aeskey);
这篇关于AES加密16字节无填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!