File tree Expand file tree Collapse file tree
src/SafeCrypt.UnitTests/AesTests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using SafeCrypt . Helpers ;
2+ using SafeCrypt . Models ;
3+ using SafeCrypt . AES ;
4+
5+ namespace SafeCrypt . UnitTests . AesTests ;
6+
7+ public class Encryption
8+ {
9+ public const string Data = "Hello, World!" ;
10+
11+ [ Fact ]
12+ public async Task EncryptToHexStringAsync_And_DecryptFromHexStringAsync_ValidParameters_ReturnsOriginalData ( )
13+ {
14+ // Arrange
15+ var aesIv = KeyGenerators . GenerateHexadecimalIVKey ( ) ;
16+ var secret = KeyGenerators . GenerateAesSecretKey ( 256 ) ;
17+
18+ var encryptionParameters = new EncryptionParameters
19+ {
20+ Data = Data ,
21+ IV = aesIv ,
22+ SecretKey = secret
23+ } ;
24+
25+ // Act
26+ var encryptedResult = await Aes . EncryptToHexStringAsync ( encryptionParameters ) ;
27+ var decryptedResult = await Aes . DecryptFromHexStringAsync ( new DecryptionParameters
28+ {
29+ Data = encryptedResult . EncryptedData ,
30+ IV = aesIv ,
31+ SecretKey = secret
32+ } ) ;
33+
34+ // Assert
35+ Assert . NotNull ( encryptedResult . EncryptedData ) ;
36+ Assert . Equal ( Data , decryptedResult . DecryptedData ) ;
37+
38+ Assert . False ( encryptedResult . HasError ) ;
39+ Assert . False ( decryptedResult . HasError ) ;
40+
41+ Assert . Empty ( encryptedResult . Errors ) ;
42+ Assert . Empty ( decryptedResult . Errors ) ;
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments