File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments