我正在尝试使用 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
被抛出?