AES,128和256无效密钥长度

1 c++ encryption aes crypto++ aes-gcm

我正在尝试使用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)
    )
);
Run Code Online (Sandbox Code Playgroud)

运行此Crypto ++时会抛出Exception:

terminate called after throwing an instance of 'CryptoPP::InvalidKeyLength'
  what():  AES/CBC: 128 is not a valid key length
Run Code Online (Sandbox Code Playgroud)

请注意,使用Wiki中提供的example.zip(并将密钥长度更改为256或128)时会发生相同的情况

有什么想法Exception被抛出?

Art*_* B. 6

字节通常是八位字节(8位).AES指定为128位块大小或16字节,也是IV的大小.AES密钥大小可以分别为128位,192位或256位或16字节,24字节或32字节.他们不能与那些不同.所以将它用于AES-256:

byte xAESKey[32];
byte xAESIv[16];
Run Code Online (Sandbox Code Playgroud)

这应该与操作模式无关.