mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core/SSL: AES-256-GCM encryption and decryption (#266)
This commit is contained in:
parent
446d84c649
commit
218ee862ef
8 changed files with 697 additions and 1 deletions
12
reference/AESEncryption/AESEncryption.upp
Normal file
12
reference/AESEncryption/AESEncryption.upp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
description "Demonstrates AES-256-GCM encryption and decryption.\377";
|
||||
|
||||
uses
|
||||
Core,
|
||||
Core/SSL;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
40
reference/AESEncryption/main.cpp
Normal file
40
reference/AESEncryption/main.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#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.");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue