mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
fix aes decryption
This commit is contained in:
parent
b9a02916cf
commit
8dc374a1bb
|
@ -126,46 +126,50 @@ struct crypto_helper
|
|||
|
||||
static std::vector<std::uint8_t> aes(const std::vector<std::uint8_t> &key,
|
||||
const std::vector<std::uint8_t> &iv,
|
||||
const std::vector<std::uint8_t> &encrypted,
|
||||
const std::vector<std::uint8_t> &source,
|
||||
cipher_chaining chaining, cipher_direction direction)
|
||||
{
|
||||
std::vector<std::uint8_t> destination(encrypted.size(), 0);
|
||||
std::vector<std::uint8_t> destination(source.size(), 0);
|
||||
|
||||
if (direction == cipher_direction::encryption && chaining == cipher_chaining::cbc)
|
||||
{
|
||||
CryptoPP::AES::Decryption aesEncryption(key.data(), key.size());
|
||||
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv.data());
|
||||
|
||||
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::ArraySink(destination.data(), destination.size()));
|
||||
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(encrypted.data()), encrypted.size());
|
||||
stfEncryptor.MessageEnd();
|
||||
}
|
||||
else if (direction == cipher_direction::decryption && chaining == cipher_chaining::cbc)
|
||||
{
|
||||
CryptoPP::AES::Encryption aesEncryption(key.data(), key.size());
|
||||
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv.data());
|
||||
|
||||
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::ArraySink(destination.data(), destination.size()));
|
||||
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(encrypted.data()), encrypted.size());
|
||||
stfEncryptor.MessageEnd();
|
||||
CryptoPP::ArraySource as(source.data(), source.size(), true,
|
||||
new CryptoPP::StreamTransformationFilter(cbcEncryption,
|
||||
new CryptoPP::ArraySink(destination.data(), destination.size()),
|
||||
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
|
||||
}
|
||||
else if (direction == cipher_direction::decryption && chaining == cipher_chaining::cbc)
|
||||
{
|
||||
CryptoPP::AES::Decryption aesDecryption(key.data(), key.size());
|
||||
CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, iv.data());
|
||||
|
||||
CryptoPP::ArraySource as(source.data(), source.size(), true,
|
||||
new CryptoPP::StreamTransformationFilter(cbcDecryption,
|
||||
new CryptoPP::ArraySink(destination.data(), destination.size()),
|
||||
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
|
||||
}
|
||||
else if (direction == cipher_direction::encryption && chaining == cipher_chaining::ecb)
|
||||
{
|
||||
CryptoPP::AES::Encryption aesEncryption(key.data(), key.size());
|
||||
CryptoPP::ECB_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv.data());
|
||||
|
||||
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::ArraySink(destination.data(), destination.size()));
|
||||
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(encrypted.data()), encrypted.size());
|
||||
stfEncryptor.MessageEnd();
|
||||
CryptoPP::ArraySource as(source.data(), source.size(), true,
|
||||
new CryptoPP::StreamTransformationFilter(cbcEncryption,
|
||||
new CryptoPP::ArraySink(destination.data(), destination.size()),
|
||||
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
|
||||
}
|
||||
else if (direction == cipher_direction::decryption && chaining == cipher_chaining::ecb)
|
||||
{
|
||||
CryptoPP::AES::Encryption aesEncryption(key.data(), key.size());
|
||||
CryptoPP::ECB_Mode_ExternalCipher::Decryption cbcEncryption(aesEncryption, iv.data());
|
||||
CryptoPP::AES::Decryption aesDecryption(key.data(), key.size());
|
||||
CryptoPP::ECB_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, iv.data());
|
||||
|
||||
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::ArraySink(destination.data(), destination.size()));
|
||||
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(encrypted.data()), encrypted.size());
|
||||
stfEncryptor.MessageEnd();
|
||||
CryptoPP::ArraySource as(source.data(), source.size(), true,
|
||||
new CryptoPP::StreamTransformationFilter(cbcDecryption,
|
||||
new CryptoPP::ArraySink(destination.data(), destination.size()),
|
||||
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
|
||||
}
|
||||
|
||||
return destination;
|
||||
|
|
Loading…
Reference in New Issue
Block a user