【发布时间】:2015-04-03 03:30:37
【问题描述】:
我正在尝试使用 Crypto++ 加密文本。上次使用 AES CTR 时效果很好,但现在使用 CBC 或 GCM 时,我可以使用的最大密钥长度为 32 位??
处理加密的代码:
string xAESPlain, xAESCipher;
AutoSeededRandomPool xRng;
byte xAESKey[128]; // Doesnt Work has to be 32 or 16
byte xAESIv[128];
xRng.GenerateBlock(xAESKey, sizeof(xAESKey));
xRng.GenerateBlock(xAESIv, sizeof(xAESIv));
CBC_Mode< AES >::Encryption E;
E.SetKeyWithIV(xAESKey, sizeof(xAESKey), xAESIv);
StringSource ss(xAESPlain, true,
new StreamTransformationFilter(E,
new StringSink(xAESCipher)
)
);
运行此 Crypto++ 时会抛出 Exception:
terminate called after throwing an instance of 'CryptoPP::InvalidKeyLength'
what(): AES/CBC: 128 is not a valid key length
请注意,使用 Wiki 中提供的 example.zip 时会发生同样的事情(并将密钥长度更改为 256 或 128)
知道为什么会抛出 Exception 吗?
【问题讨论】:
-
“使用 Wiki 中提供的 example.zip 时也会发生同样的情况” - 我怀疑 wiki 是否提供了使用 128 字节密钥的示例。如果你能引用它,那么我可以修复它。
标签: c++ encryption aes crypto++ aes-gcm