#ifndef A89D0C3C_4F05_4631_A720_D8B2CEA5E99A #define A89D0C3C_4F05_4631_A720_D8B2CEA5E99A #include #include #include #include #include #include #include #include #include #include #include #include "Logger.h" namespace Util { class AESUtil { public: static std::string encryptAES(const std::string& plaintext, const std::string& key, const std::string& iv) { try { Poco::Crypto::CipherKey cipherKey("aes-256-cbc", key, iv); Poco::Crypto::CipherFactory& factory = Poco::Crypto::CipherFactory::defaultFactory(); std::unique_ptr pCipher(factory.createCipher(cipherKey)); std::string ciphertext = pCipher->encryptString(plaintext, Poco::Crypto::Cipher::ENC_BASE64_NO_LF); return ciphertext; } catch (const Poco::Exception& e) { logger().error("encryptAES error: %s", std::string(e.what())); return ""; } } static std::string decryptAES(const std::string& ciphertext, const std::string& key, const std::string& iv) { try { Poco::Crypto::CipherKey cipherKey("aes-256-cbc", key, iv); Poco::Crypto::CipherFactory& factory = Poco::Crypto::CipherFactory::defaultFactory(); std::unique_ptr pCipher(factory.createCipher(cipherKey)); std::string plaintext = pCipher->decryptString(ciphertext, Poco::Crypto::Cipher::ENC_BASE64_NO_LF); return plaintext; } catch (const Poco::Exception& e) { logger().error("decryptAES error: %s", std::string(e.what())); return ""; } } }; } #endif