@@ -10,19 +10,26 @@ namespace SafeCrypt.UnitTests.RsaTests;
1010
1111public class RsaTests
1212{
13+ private readonly string PublicKey ;
14+ private readonly string PrivateKey ;
15+ public RsaTests ( )
16+ {
17+ ( PublicKey , PrivateKey ) = KeyGenerators . GenerateRsaKeys ( 2048 ) ;
18+ }
19+
1320 [ Fact ]
1421 public async Task EncryptAsync_DecryptAsync_ValidParameters_ReturnsOriginalData ( )
1522 {
1623 // Example: Generate RSA keys
17- var rsaKeyPair = KeyGenerators . GenerateRsaKeys ( 2048 ) ;
18- string rsaPublicKey = rsaKeyPair . Item1 ;
19- string rsaPrivateKey = rsaKeyPair . Item2 ;
24+ // var rsaKeyPair = KeyGenerators.GenerateRsaKeys(2048);
25+ // string rsaPublicKey = rsaKeyPair.Item1;
26+ // string rsaPrivateKey = rsaKeyPair.Item2;
2027
2128 // Arrange
2229 var model = new RsaEncryptionParameters
2330 {
2431 DataToEncrypt = "Hello, RSA!" ,
25- PublicKey = rsaPublicKey
32+ PublicKey = PublicKey
2633 } ;
2734
2835 // Act
@@ -31,7 +38,7 @@ public async Task EncryptAsync_DecryptAsync_ValidParameters_ReturnsOriginalData(
3138 var decryptModel = new RsaDecryptionParameters
3239 {
3340 DataToDecrypt = encrypt . EncryptedData ,
34- PrivateKey = rsaPrivateKey
41+ PrivateKey = PrivateKey
3542 } ;
3643
3744 var decrypt = await Rsa . DecryptAsync ( decryptModel ) ;
@@ -43,4 +50,22 @@ public async Task EncryptAsync_DecryptAsync_ValidParameters_ReturnsOriginalData(
4350 Assert . NotNull ( decrypt . DecryptedData ) ;
4451 Assert . Empty ( decrypt . Errors ) ;
4552 }
53+
54+ [ Fact ]
55+ public async Task EncryptAsync_InvalidData_ReturnsErrors ( )
56+ {
57+ // Arrange
58+ var model = new RsaEncryptionParameters
59+ {
60+ DataToEncrypt = "" ,
61+ PublicKey = PublicKey
62+ } ;
63+
64+ // Act
65+ var result = await Rsa . EncryptAsync ( model ) ;
66+
67+ // Assert
68+ Assert . Null ( result . EncryptedData ) ;
69+ Assert . NotEmpty ( result . Errors ) ;
70+ }
4671}
0 commit comments