mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include <Core/Core.h>
|
|
#include <Core/SSL/SSL.h>
|
|
|
|
using namespace Upp;
|
|
|
|
CONSOLE_APP_MAIN
|
|
{
|
|
StdLogSetup(LOG_COUT | LOG_FILE);
|
|
|
|
const String plaintext = "Secret message: Doomsday code is 12345.";
|
|
const String password = "password123456!@#";
|
|
|
|
String encrypted, decrypted;
|
|
|
|
// Encrypt
|
|
if(encrypted = AES256Encrypt(plaintext, password); !encrypted.IsVoid()) {
|
|
RLOG("Encryption successful.");
|
|
RLOG("Encrypted data (hex): " << HexString(encrypted));
|
|
}
|
|
else {
|
|
RLOG("Encryption failed.");
|
|
return;
|
|
}
|
|
|
|
// Decrypt
|
|
if(decrypted = AES256Decrypt(encrypted, password); !decrypted.IsVoid()) {
|
|
RLOG("Decryption successful.");
|
|
RLOG("Decrypted text: " << decrypted);
|
|
}
|
|
else {
|
|
RLOG("Decryption failed.");
|
|
return;
|
|
}
|
|
|
|
// Check if original matches decrypted
|
|
if(decrypted == plaintext)
|
|
RLOG("Roundtrip successful: Decrypted text matches original.");
|
|
else
|
|
RLOG("Roundtrip failed: Data mismatch.");
|
|
}
|