问题描述
我有解码 AES 256 字符串的函数,但它只返回 16 个字符
I had function that decode AES 256 string but it return only 16 char
bool decrypt_block(unsigned char* cipherText, unsigned char* plainText, unsigned char* key)
{
AES_KEY decKey;
if (AES_set_decrypt_key(key, 256, &decKey) < 0)
return false;
AES_decrypt(cipherText, plainText, &decKey);
return true;
}
decrypt_block( encoded, resultText, ( unsigned char *) "57f4dad48e7a4f7cd171c654226feb5a");
任何想法
推荐答案
您似乎混淆了密钥长度和块大小.
It appears that you are confusing key length and block size.
AES 可用于 3 种不同的密钥长度:128 位、192 位和256 位.
AES can be used with 3 different key lengths: 128-bits, 192-bits & 256-bits.
AES 始终使用 128 位(16 字节)的块大小.对于长度超过 16 个字节的消息,您需要一次解密(或加密)16 个字节,并期望每次获得 16 个字节的输出.(您还需要决定使用哪种模式 - 例如 CBC、CTR、ECB 等.如果您正在解密其他人提供的文本,那么该决定已经为您做出.如果为自己做出决定,请承担请记住,ECB 几乎从来都不是正确的选择.)如果消息不是 16 字节长的倍数,您需要填充 使其成为.PKCS #7 填充是最常见的.
AES always uses a block size of 128 bits (16 bytes). For messages that are more than 16 bytes long, you need to decrypt (or encrypt) 16 bytes at a time and expect to get 16 bytes of output each time. (You will also need to decide which mode to use - e.g. CBC, CTR, ECB, etc.. If you're decrypting text provided by somebody else then that decision has already been taken for you. If making the decision for yourself, bear in mind that ECB is almost never the right choice.) If the message isn't a multiple of 16 bytes long, you'll need to pad it so that it is. PKCS #7 padding is the most common.
有关详细信息,请参阅维基百科关于 AES 的文章.
See the Wikipedia article on AES for more information.
这篇关于AES ECB 加密/解密仅解密前 16 个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!