File tree Expand file tree Collapse file tree
src/SafeCrypt.UnitTests/RsaTests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using SafeCrypt . Helpers ;
2+ using SafeCrypt . RsaEncryption ;
3+ using System ;
4+ using System . Collections . Generic ;
5+ using System . Linq ;
6+ using System . Text ;
7+ using System . Threading . Tasks ;
8+
9+ namespace SafeCrypt . UnitTests . RsaTests ;
10+
11+ public class RsaTests
12+ {
13+ [ Fact ]
14+ public async Task EncryptAsync_DecryptAsync_ValidParameters_ReturnsOriginalData ( )
15+ {
16+ // Example: Generate RSA keys
17+ var rsaKeyPair = KeyGenerators . GenerateRsaKeys ( 2048 ) ;
18+ string rsaPublicKey = rsaKeyPair . Item1 ;
19+ string rsaPrivateKey = rsaKeyPair . Item2 ;
20+
21+ // Arrange
22+ var model = new RsaEncryptionParameters
23+ {
24+ DataToEncrypt = "Hello, RSA!" ,
25+ PublicKey = rsaPublicKey
26+ } ;
27+
28+ // Act
29+ var encrypt = await Rsa . EncryptAsync ( model ) ;
30+
31+ var decryptModel = new RsaDecryptionParameters
32+ {
33+ DataToDecrypt = encrypt . EncryptedData ,
34+ PrivateKey = rsaPrivateKey
35+ } ;
36+
37+ var decrypt = await Rsa . DecryptAsync ( decryptModel ) ;
38+
39+ // Assert
40+ Assert . Equal ( model . DataToEncrypt , decrypt . DecryptedData ) ;
41+ Assert . NotNull ( encrypt . EncryptedData ) ;
42+ Assert . Empty ( encrypt . Errors ) ;
43+ Assert . NotNull ( decrypt . DecryptedData ) ;
44+ Assert . Empty ( decrypt . Errors ) ;
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments