脚本宝典收集整理的这篇文章主要介绍了UE4 CryptoPP 5.6.5 加解密矩阵验证结果,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
Crypto++ 5.6.5
密码与偏移量:
static SecByteBlock GetKey(std::string KeyStr) { SecByteBlock key(AES::MAX_KEYLENGTH); memset(key, 0x30, key.size()); KeyStr.size() <= AES::MAX_KEYLENGTH ? memcpy(key, KeyStr.c_str(), KeyStr.size()) : memcpy(key, KeyStr.c_str(), AES::MAX_KEYLENGTH); return key; } //convert string to byte static SecByteBlock GetIV(std::string KeyStr, const std::string IVStr) { SecByteBlock IV(AES::BLOCKSIZE); memset(IV, 0x30, IV.size()); KeyStr.size() <= AES::BLOCKSIZE ? memcpy(IV, IVStr.c_str(), IVStr.size()) : memcpy(IV, IVStr.c_str(), AES::BLOCKSIZE); return IV; }
加解密过程(包含输出 string 及 file):
UFUNCTION(BlueprintCallable, Category = "AES") static void CBC_StringEncrypto(const FString aes_content, FString& aes_encrypt_content, const FString aes_key = TEXT("1234567890123456"), const FString aes_IV = TEXT("ahbdgteyusnjkldu")) { const std::string plaintext = TCHAR_TO_UTF8(*aes_content); // Initialise the key and IV SecByteBlock key = GetKey(TCHAR_TO_UTF8(*aes_key)); SecByteBlock iv = GetIV(TCHAR_TO_UTF8(*aes_key), TCHAR_TO_UTF8(*aes_IV)); // Encrypt AES::Encryption cipher(key, AES::MAX_KEYLENGTH); CBC_Mode_ExternalCipher::Encryption encryption(cipher, iv); std::string cipher_text; StreamTransformationFilter filter(encryption, new StringSink(cipher_text)); //使用填充并通过 HexEncoder 编码将 cipher_text 密文转成可以正常打印阅读的密文,但是无法正常解码?????????? //StreamTransformationFilter filter(encryption, new HexEncoder(new StringSink(cipher_text)), BlockPaddingSchemeDef::BlockPaddingScheme::ZEROS_PADDING); filter.Put(reinterpret_cast<const byte*>(plaintext.c_str()), plaintext.size()); filter.MessageEnd(); //存输出的 string 密文 std::string cipherOut; StringSource(cipher_text, true, new HexEncoder(new StringSink(cipherOut))); //to lower //std::string str = _strlwr(TCHAR_TO_ANSI((UTF8_TO_TCHAR(cipher_text.c_str())))); aes_encrypt_content = cipherOut.c_str(); } UFUNCTION(BlueprintCallable, Category = "AES") static void CBC_StringDecrypto(const FString aes_encrypt_content, FString& aes_content, const FString aes_key = TEXT("1234567890123456"), const FString aes_IV = TEXT("ahbdgteyusnjkldu")) { //存明文 std::string cipher_text; //对密文先进行 Decoder 为明文 StringSource(TCHAR_TO_UTF8(*aes_encrypt_content), true, new HexDecoder(new StringSink(cipher_text))); //存输出的 string 明文 std::string decrypted_text; //Initialise the key and IV SecByteBlock key = GetKey(TCHAR_TO_UTF8(*aes_key)); SecByteBlock iv = GetIV(TCHAR_TO_UTF8(*aes_key), TCHAR_TO_UTF8(*aes_IV)); // Decrypt AES::Decryption cipher(key, AES::MAX_KEYLENGTH); CBC_Mode_ExternalCipher::Decryption decryption(cipher, iv); StreamTransformationFilter filter(decryption, new StringSink(decrypted_text)); //使用填充并通过 HexEncoder 编码将 cipher_text 密文转成可以正常阅读的明文,无法正常解码使用?????????? //StreamTransformationFilter filter(decryption, new HexEncoder(new StringSink(decrypted_text)), BlockPaddingSchemeDef::BlockPaddingScheme::ZEROS_PADDING); filter.Put(reinterpret_cast<const byte*>(cipher_text.c_str()), cipher_text.size()); filter.MessageEnd(); aes_content = UTF8_TO_TCHAR(decrypted_text.c_str()); } UFUNCTION(BlueprintCallable, Category = "AES") static void CBC_AESFileEncrypto(const FString aes_key = TEXT("1234567890123456"), const FString aes_IV = TEXT("ahbdgteyusnjkldu")) { FString OriginalPath = FPaths::ProjectContentDir() + "\" + TEXT("original.txt"); const std::string original_file = TCHAR_TO_UTF8(*OriginalPath); FString EncryptPath = FPaths::ProjectContentDir() + "\" + TEXT("encrypted.txt"); const std::string encrypto_file = TCHAR_TO_UTF8(*EncryptPath); // Initialise the key and IV SecByteBlock key = GetKey(TCHAR_TO_UTF8(*aes_key)); SecByteBlock iv = GetIV(TCHAR_TO_UTF8(*aes_key), TCHAR_TO_UTF8(*aes_IV)); // Read the file contents to a string and output to cout. Safest to read // contents as binary data, although non-printable characters shouldn't be // output to cout. std::ifstream infile(original_file.c_str(), std::ios::binary); const std::string plaintext((std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>()); infile.close(); std::cout << "Plain Text (" << plaintext.size() << " bytes)n" << plaintext << "nn"; // Encrypt AES::Encryption cipher(key, AES::MAX_KEYLENGTH); CBC_Mode_ExternalCipher::Encryption encryption(cipher, iv); std::string cipher_text; StreamTransformationFilter filter(encryption, new StringSink(cipher_text)); //使用填充并通过 HexEncoder 编码将 cipher_text 密文转成可以正常打印阅读的密文,但是无法正常解码?????????? //StreamTransformationFilter filter(encryption, new HexEncoder(new StringSink(cipher_text)), BlockPaddingSchemeDef::BlockPaddingScheme::PKCS_PADDING, true); filter.Put(reinterpret_cast<const byte*>(plaintext.c_str()), plaintext.size()); filter.MessageEnd(); //to lower //std::string str = _strlwr(TCHAR_TO_ANSI((UTF8_TO_TCHAR(cipher_text.c_str())))); // Dump cipher text std::ofstream outfile(encrypto_file.c_str(), std::ios::binary); outfile.write(cipher_text.c_str(), cipher_text.size()); outfile.close(); } UFUNCTION(BlueprintCallable, Category = "AES") static void CBC_AESFileDecrypto(const FString aes_key = TEXT("1234567890123456"), const FString aes_IV = TEXT("ahbdgteyusnjkldu")) { FString EncryptPath = FPaths::ProjectContentDir() + "\" + TEXT("encrypted.txt"); const std::string encrypto_file = TCHAR_TO_UTF8(*EncryptPath); FString DecryptoPath = FPaths::ProjectContentDir() + "\" + TEXT("decrypted.txt"); const std::string decrypto_file = TCHAR_TO_UTF8(*DecryptoPath); //Initialise the key and IV SecByteBlock key = GetKey(TCHAR_TO_UTF8(*aes_key)); SecByteBlock iv = GetIV(TCHAR_TO_UTF8(*aes_key), TCHAR_TO_UTF8(*aes_IV)); // Read the encrypted file contents to a string as binary data. std::ifstream infile(encrypto_file.c_str(), std::ios::binary); const std::string cipher_text((std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>()); infile.close(); // Decrypt CryptoPP::AES::Decryption cipher(key, AES::MAX_KEYLENGTH); CryptoPP::CBC_Mode_ExternalCipher::Decryption decryption(cipher, iv); std::string decrypted_test; StreamTransformationFilter filter(decryption, new CryptoPP::StringSink(decrypted_test)); //使用填充并通过 HexEncoder 编码将 cipher_text 密文转成可以正常阅读的明文,无法正常解码使用?????????? //StreamTransformationFilter filter(decryption, new HexEncoder(new StringSink(decrypted_test)), BlockPaddingSchemeDef::BlockPaddingScheme::PKCS_PADDING, true); filter.Put(reinterpret_cast<const byte*>(cipher_text.c_str()), cipher_text.size()); filter.MessageEnd(); // Dump decrypted text std::ofstream outfile(decrypto_file.c_str(), std::ios::binary); outfile.write(decrypted_test.c_str(), decrypted_test.size()); outfile.close(); }
【原始明文】:{"deadline_time":"1670428800","max_time":"8640000","msg":"","status":"1"}密文转可输出打印密文:【Encrypto】DEFAULT_PADDING:39443135363145463843433936363741414330463633413537463942323737413543323345333241353843454330383042344439424444384335393834323438313844443830374339443836353236323841363142303437323946443541323132304632364330343937334541383330463446444445394339393533393334383235443344323432423934454331324441424633303934444138453532323432【Decrypto】不设置 PADDING 参数:Crash 无法解密【Decrypto】NO_PADDING:4B2F70804BB4CFD54CE327D5C6507CC3C461587F01AB2A06DBB8392C78429EEA979ABD6E80486E1A2A83C6F836F7E0AB20DC186168BE3D9875815E988541112A52E5AFC658A93E112681BCAABF8185C1F1C0C0AD02EC76202B2DFF5D150FD10A82CDCCF5AE79467D7F85CADD3A1A1D62D8231E07B818B50A06A35C473B6ADCB2E62CD3C40C92AB3CE3B326B2C9B2F864C4A90FD6B70C6AC5D60B1442551F30D9【Decrypto】ONE_AND_ZEROS_PADDING:Crash 无法解密【Decrypto】PKCS_PADDING:Crash 无法解密【Decrypto】ZEROS_PADDING:4B2F70804BB4CFD54CE327D5C6507CC3C461587F01AB2A06DBB8392C78429EEA979ABD6E80486E1A2A83C6F836F7E0AB20DC186168BE3D9875815E988541112A52E5AFC658A93E112681BCAABF8185C1F1C0C0AD02EC76202B2DFF5D150FD10A82CDCCF5AE79467D7F85CADD3A1A1D62D8231E07B818B50A06A35C473B6ADCB2E62CD3C40C92AB3CE3B326B2C9B2F864C4A90FD6B70C6AC5D60B1442551F30D9【Encrypto】NO_PADDING: Crash 无法加密【Encrypto】ONE_AND_ZEROS_PADDING:39443135363145463843433936363741414330463633413537463942323737413543323345333241353843454330383042344439424444384335393834323438313844443830374339443836353236323841363142303437323946443541323132304632364330343937334541383330463446444445394339393533393334383532413130453835433841363130433434303441354535353630423833373933【Decrypto】不设置 PADDING 参数:Crash 无法解密【Decrypto】NO_PADDING:4B2F70804BB4CFD54CE327D5C6507CC3C461587F01AB2A06DBB8392C78429EEA979ABD6E80486E1A2A83C6F836F7E0AB20DC186168BE3D9875815E988541112A52E5AFC658A93E112681BCAABF8185C1F1C0C0AD02EC76202B2DFF5D150FD10A82CDCCF5AE79467D7F85CADD3A1A1D62D8231E07B818B50A06A35C473B6ADCB2B86D50FD09AE5C9FE899F67C2B387967BEEE7DDB67D253A01A8F3ECBDEC864B9【Decrypto】ONE_AND_ZEROS_PADDING:Crash 无法解密【Decrypto】PKCS_PADDING:Crash 无法解密【Decrypto】ZEROS_PADDING:4B2F70804BB4CFD54CE327D5C6507CC3C461587F01AB2A06DBB8392C78429EEA979ABD6E80486E1A2A83C6F836F7E0AB20DC186168BE3D9875815E988541112A52E5AFC658A93E112681BCAABF8185C1F1C0C0AD02EC76202B2DFF5D150FD10A82CDCCF5AE79467D7F85CADD3A1A1D62D8231E07B818B50A06A35C473B6ADCB2B86D50FD09AE5C9FE899F67C2B387967BEEE7DDB67D253A01A8F3ECBDEC864B9【Encrypto】PKCS_PADDING:39443135363145463843433936363741414330463633413537463942323737413543323345333241353843454330383042344439424444384335393834323438313844443830374339443836353236323841363142303437323946443541323132304632364330343937334541383330463446444445394339393533393334383235443344323432423934454331324441424633303934444138453532323432【Decrypto】不设置 PADDING 参数:Crash 无法解密【Decrypto】NO_PADDING:4B2F70804BB4CFD54CE327D5C6507CC3C461587F01AB2A06DBB8392C78429EEA979ABD6E80486E1A2A83C6F836F7E0AB20DC186168BE3D9875815E988541112A52E5AFC658A93E112681BCAABF8185C1F1C0C0AD02EC76202B2DFF5D150FD10A82CDCCF5AE79467D7F85CADD3A1A1D62D8231E07B818B50A06A35C473B6ADCB2E62CD3C40C92AB3CE3B326B2C9B2F864C4A90FD6B70C6AC5D60B1442551F30D9【Decrypto】ONE_AND_ZEROS_PADDING:Crash 无法解密【Decrypto】PKCS_PADDING:Crash 无法解密【Decrypto】ZEROS_PADDING:4B2F70804BB4CFD54CE327D5C6507CC3C461587F01AB2A06DBB8392C78429EEA979ABD6E80486E1A2A83C6F836F7E0AB20DC186168BE3D9875815E988541112A52E5AFC658A93E112681BCAABF8185C1F1C0C0AD02EC76202B2DFF5D150FD10A82CDCCF5AE79467D7F85CADD3A1A1D62D8231E07B818B50A06A35C473B6ADCB2E62CD3C40C92AB3CE3B326B2C9B2F864C4A90FD6B70C6AC5D60B1442551F30D9【Encrypto】ZEROS_PADDING:39443135363145463843433936363741414330463633413537463942323737413543323345333241353843454330383042344439424444384335393834323438313844443830374339443836353236323841363142303437323946443541323132304632364330343937334541383330463446444445394339393533393334384130344341434130443744384439373239363538334535384232433134303539【Decrypto】不设置 PADDING 参数:Crash 无法解密【Decrypto】NO_PADDING:4B2F70804BB4CFD54CE327D5C6507CC3C461587F01AB2A06DBB8392C78429EEA979ABD6E80486E1A2A83C6F836F7E0AB20DC186168BE3D9875815E988541112A52E5AFC658A93E112681BCAABF8185C1F1C0C0AD02EC76202B2DFF5D150FD10A82CDCCF5AE79467D7F85CADD3A1A1D62D8231E07B818B50A06A35C473B6ADCB27F47A62FCB2E5D8971C710AB3BA4A86FEBA714FB6A98FCAB151F89C35181C8BF【Decrypto】ONE_AND_ZEROS_PADDING:Crash 无法解密【Decrypto】PKCS_PADDING:Crash 无法解密【Decrypto】ZEROS_PADDING:4B2F70804BB4CFD54CE327D5C6507CC3C461587F01AB2A06DBB8392C78429EEA979ABD6E80486E1A2A83C6F836F7E0AB20DC186168BE3D9875815E988541112A52E5AFC658A93E112681BCAABF8185C1F1C0C0AD02EC76202B2DFF5D150FD10A82CDCCF5AE79467D7F85CADD3A1A1D62D8231E07B818B50A06A35C473B6ADCB27F47A62FCB2E5D8971C710AB3BA4A86FEBA714FB6A98FCAB151F89C35181C8BF【Encrypto】不设置 PADDING 参数(源码默认是 DEFAULT_PADDING):9D1561EF8CC9667AAC0F63A57F9B277A5C23E32A58CEC080B4D9BDD8C598424818DD807C9D8652628A61B04729FD5A2120F26C04973EA830F4FDDE9C9953934825D3D242B94EC12DABF3094DA8E52242【Decrypto】不设置 PADDING 参数:{"deadline_time":"1670428800","max_time":"8640000","msg":"","status":"1"}【Decrypto】NO_PADDING:7B22646561646C696E655F74696D65223A2231363730343238383030222C226D61785F74696D65223A2238363430303030222C226D7367223A22222C22737461747573223A2231227D07070707070707【Decrypto】ONE_AND_ZEROS_PADDING:Crash 无法解密【Decrypto】PKCS_PADDING:7B22646561646C696E655F74696D65223A2231363730343238383030222C226D61785F74696D65223A2238363430303030222C226D7367223A22222C22737461747573223A2231227D【Decrypto】ZEROS_PADDING:7B22646561646C696E655F74696D65223A2231363730343238383030222C226D61785F74696D65223A2238363430303030222C226D7367223A22222C22737461747573223A2231227D07070707070707
WEB AES 验证工具:
https://www.ssleye.com/ssltool/aes_cipher.html
https://www.javainuse.com/aesgenerator
https://the-x.cn/en-us/cryptography/Aes.aspx
相关话题:
http://elmagnifico.tech/2021/01/08/Crypto++-padding/
https://gameinstitute.qq.com/community/detail/121437
https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
https://www.codenong.com/43967330/
https://coderedirect.com/questions/212416/encrypt-decrypt-with-aes-using-c-c
https://stackoverflow.com/questions/43967330/crypto-aes-256-ecb-result-is-different-with-openssl
https://blog.csdn.net/qq_35649764/article/details/83036230?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0.highlightwordscore&spm=1001.2101.3001.4242.1
https://blog.csdn.net/suhiymof/article/details/92796811
以上是脚本宝典为你收集整理的UE4 CryptoPP 5.6.5 加解密矩阵验证结果全部内容,希望文章能够帮你解决UE4 CryptoPP 5.6.5 加解密矩阵验证结果所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。