Core/SSL: AES-256-GCM encryption and decryption (#266)

This commit is contained in:
İsmail Yılmaz 2025-05-05 15:31:58 +03:00 committed by GitHub
parent 446d84c649
commit 218ee862ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 697 additions and 1 deletions

View file

@ -0,0 +1,12 @@
description "Demonstrates AES-256-GCM encryption and decryption.\377";
uses
Core,
Core/SSL;
file
main.cpp;
mainconfig
"" = "";

View 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.");
}