Skip to content

Commit 15966a4

Browse files
committed
Create AES usage classs
1 parent ab64d5a commit 15966a4

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using SafeCrypt.AES;
2+
using SafeCrypt.Models;
3+
4+
namespace SafeCrypt.App.Usage;
5+
6+
internal static class AesUsage
7+
{
8+
internal static async void Execute()
9+
{
10+
Console.WriteLine("------- AES Test Started -------");
11+
12+
var dataToEncrypt = "Data to Encrypt";
13+
var secret = "hghjuytsdfraestwsgtere==";
14+
15+
// Encryption process
16+
// this method generates a random IV key for the encryption process
17+
// the IV is returned in the response with other properties
18+
var response = await Aes.EncryptToBase64StringAsync(dataToEncrypt, secret);
19+
20+
Console.WriteLine("............Encryption Started............");
21+
22+
Console.WriteLine($"Encrypted data: {response.EncryptedData}");
23+
Console.WriteLine($"IV key: {response.Iv}");
24+
Console.WriteLine($"Secret key: {response.SecretKey}");
25+
26+
Console.WriteLine();
27+
28+
// Decryption process
29+
var decryptorParam = new DecryptionParameters
30+
{
31+
IV = response.Iv,
32+
SecretKey = secret,
33+
Data = response.EncryptedData
34+
};
35+
36+
var decryptionData = await Aes.DecryptFromBase64StringAsync(decryptorParam);
37+
38+
Console.WriteLine("............Decryption Started............");
39+
Console.WriteLine($"Decrypted data: {decryptionData.DecryptedData}");
40+
Console.WriteLine($"IV key: {decryptionData.Iv}");
41+
Console.WriteLine($"Secret key: {decryptionData.SecretKey}");
42+
43+
Console.WriteLine();
44+
45+
Console.WriteLine("------- AES Test Ended -------");
46+
47+
}
48+
}

0 commit comments

Comments
 (0)