11using SafeCrypt . Helpers ;
22using SafeCrypt . Models ;
33using SafeCrypt . AES ;
4+ using SafeCrypt . RsaEncryption . Models ;
45
56namespace SafeCrypt . UnitTests . AesTests ;
67
@@ -23,22 +24,57 @@ public async Task EncryptToHexStringAsync_And_DecryptFromHexStringAsync_ValidPar
2324 } ;
2425
2526 // Act
26- var encryptedResult = await Aes . EncryptToHexStringAsync ( encryptionParameters ) ;
27- var decryptedResult = await Aes . DecryptFromHexStringAsync ( new DecryptionParameters
27+ var encryptionResult = await Aes . EncryptToHexStringAsync ( encryptionParameters ) ;
28+ Assert . False ( encryptionResult . HasError ) ;
29+
30+ var decryptionResult = await Aes . DecryptFromHexStringAsync ( new DecryptionParameters
2831 {
29- Data = encryptedResult . EncryptedData ,
32+ Data = encryptionResult . EncryptedData ,
3033 IV = aesIv ,
3134 SecretKey = secret
3235 } ) ;
3336
3437 // Assert
35- Assert . NotNull ( encryptedResult . EncryptedData ) ;
36- Assert . Equal ( Data , decryptedResult . DecryptedData ) ;
38+ Assert . NotNull ( encryptionResult . EncryptedData ) ;
39+ Assert . Equal ( Data , decryptionResult . DecryptedData ) ;
3740
38- Assert . False ( encryptedResult . HasError ) ;
39- Assert . False ( decryptedResult . HasError ) ;
41+ Assert . False ( encryptionResult . HasError ) ;
42+ Assert . False ( decryptionResult . HasError ) ;
4043
41- Assert . Empty ( encryptedResult . Errors ) ;
42- Assert . Empty ( decryptedResult . Errors ) ;
44+ Assert . Empty ( encryptionResult . Errors ) ;
45+ Assert . Empty ( decryptionResult . Errors ) ;
46+ }
47+
48+ [ Theory ]
49+ [ InlineData ( Data ) ]
50+ public async Task EncryptToBase64StringAndDecryptAsync_DecryptedDataMatchesOriginalData ( string originalData )
51+ {
52+ // Arrange
53+ var aesIv = KeyGenerators . GenerateBase64IVKey ( ) ;
54+ var secret = KeyGenerators . GenerateAesSecretKey ( 256 ) ;
55+
56+ var encryptionParameters = new EncryptionParameters
57+ {
58+ Data = originalData ,
59+ IV = aesIv ,
60+ SecretKey = secret
61+ } ;
62+
63+ // Act
64+ var encryptionResult = await Aes . EncryptToBase64StringAsync ( encryptionParameters ) ;
65+ Assert . False ( encryptionResult . HasError ) ;
66+
67+ var decryptionParameters = new DecryptionParameters
68+ {
69+ Data = encryptionResult . EncryptedData ,
70+ IV = aesIv ,
71+ SecretKey = secret
72+ } ;
73+
74+ var decryptionResult = await Aes . DecryptFromBase64StringAsync ( decryptionParameters ) ;
75+ Assert . False ( decryptionResult . HasError ) ;
76+
77+ // Assert
78+ Assert . Equal ( originalData , decryptionResult . DecryptedData ) ;
4379 }
4480}
0 commit comments