简体   繁体   English

Botan/C++ - 使用大于 32 字节的密钥大小使用 AES 进行加密

[英]Botan/C++ - Encrypting with AES using a key size larger than 32 bytes

I need to encrypt with AES-256, but I ALSO need a key size LARGER than 32 bytes.我需要用 AES-256 加密,但我还需要一个大于 32 字节的密钥大小。 I have a function that takes text, a key, and an IV, and returns the encrypted text.我有一个接受文本、密钥和 IV 并返回加密文本的函数。 It works with everything smaller than 32 bytes, but anything larger gives me an error.它适用于小于 32 字节的所有内容,但任何更大的内容都会给我一个错误。

So essentially, how can I implement a way to use keys larger than 32 bytes?所以本质上,我如何实现一种使用大于 32 字节的键的方法? I've already tried splitting the key into a vector of 32-byte (or less) strings, then using those as the keys, but I couldn't figure out a way to uniformly encrypt the text with all of those keys at once, so what can I do?我已经尝试将密钥拆分为 32 字节(或更少)字符串的向量,然后将它们用作密钥,但我无法找到一种方法来一次性使用所有这些密钥对文本进行统一加密,那我该怎么办?

With AES-256 the key size is always 32 bytes long (256/8 = 32).对于 AES-256,密钥大小始终为 32 字节长 (256/8 = 32)。

When the input secret is not exactly 32 bytes and/or of poor quality, a key derivation function is used.当输入秘密不是正好 32 字节和/或质量较差时,使用密钥推导函数 With keys of sufficient entropy a simple hashing function such as SHA-256, is sufficient.对于具有足够熵的密钥,一个简单的散列函数(例如 SHA-256)就足够了。

In other words, just feed your input key through SHA-256 and out comes a 32-byte key usable for AES-256.换句话说,只需通过 SHA-256 输入您的输入密钥,然后输出一个可用于 AES-256 的 32 字节密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM