我一直在尝试使用AES加密使用Crypto ++加密/解密字节数组,但我遇到了这个例外:
StreamTransformationFilter: ciphertext length is not a multiple of block size
问题是我使用的是PKCS填充,所以这不应该发生。
这是我遇到麻烦的功能。谁能告诉我到底出错了什么?
void QtAES256::decrypt(const QByteArray& cryptedArray, QByteArray& decryptedArray) const
{
CBC_Mode<AES>::Decryption cbcDecryption(reinterpret_cast<const byte*>(m_Key.constData()),
m_Key.length(),
reinterpret_cast<const byte*>(m_IV.constData()));
byte decryptedResult[MAXSIZE];
ArraySink* arraySink = new ArraySink(decryptedResult, MAXSIZE);
StreamTransformationFilter stfDecryptor(cbcDecryption,
arraySink,
StreamTransformationFilter::PKCS_PADDING);
stfDecryptor.Put(reinterpret_cast<const byte*>(cryptedArray.constData()), cryptedArray.length());
try
{
stfDecryptor.MessageEnd();
}
catch(InvalidCiphertext &e)
{
qDebug() << e.what();
}
decryptedArray = QByteArray(reinterpret_cast<const char*>(decryptedResult), arraySink->TotalPutLength());
delete arraySink;
}