2021-12-06 02:58:35 +01:00
|
|
|
#include <iostream>
|
2022-05-22 13:07:40 +02:00
|
|
|
#include <GCrypt/GWrapper.h>
|
2022-05-16 22:35:28 +02:00
|
|
|
#include <GCrypt/SecureBitset.h>
|
|
|
|
#include <GCrypt/Util.h>
|
|
|
|
#include <GCrypt/InitializationVector.h>
|
2022-05-22 13:43:23 +02:00
|
|
|
#include <GCrypt/Key.h>
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:15:34 +02:00
|
|
|
using namespace Leonetienne::GCrypt;
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
void ExampleString() {
|
|
|
|
std::cout << "Example on how to encrypt & decrypt a string:" << std::endl;
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
// Get some string
|
|
|
|
const std::string input = "I am a super secret message!";
|
|
|
|
std::cout << input << std::endl;
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
// Encrypt
|
2022-05-22 13:43:23 +02:00
|
|
|
const std::string encrypted = GWrapper::EncryptString(input, Key::FromPassword("password1"));
|
2022-05-16 22:01:52 +02:00
|
|
|
std::cout << encrypted << std::endl;
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
// Decrypt
|
2022-05-22 13:43:23 +02:00
|
|
|
const std::string decrypted = GWrapper::DecryptString(encrypted, Key::FromPassword("password1"));
|
2022-05-16 22:01:52 +02:00
|
|
|
std::cout << decrypted << std::endl;
|
|
|
|
|
|
|
|
return;
|
2021-12-06 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
void ExampleFiles() {
|
|
|
|
std::cout << "Example on how to encrypt & decrypt any file:" << std::endl;
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
// Encrypt
|
2022-05-22 13:43:23 +02:00
|
|
|
GWrapper::EncryptFile("main.cpp", "main.cpp.crypt", Key::FromPassword("password1"));
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
// Decrypt
|
2022-05-22 13:43:23 +02:00
|
|
|
GWrapper::DecryptFile("main.cpp.crypt", "main.cpp.clear", Key::FromPassword("password1"));
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
return;
|
2021-12-06 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
int main() {
|
|
|
|
ExampleString();
|
|
|
|
//ExampleFiles();
|
2021-12-06 02:58:35 +01:00
|
|
|
|
2022-05-16 22:01:52 +02:00
|
|
|
return 0;
|
2021-12-06 02:58:35 +01:00
|
|
|
}
|
2022-05-16 22:01:52 +02:00
|
|
|
|