AES ECB加密/解密仅解密前16个字节 [英] AES ECB encrypt/decrypt only decrypts the first 16 bytes

查看:1080
本文介绍了AES ECB加密/解密仅解密前16个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有解码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字节的倍数,则需要

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个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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