33using System . Text ;
44using Xunit ;
55using NETCore . Encrypt ;
6+ using System . Security . Cryptography ;
67
78namespace NETCore . Encrypt . Tests
89{
@@ -27,7 +28,6 @@ public void Create_RSAKey_Test(RsaSize size)
2728 }
2829
2930 [ Theory ]
30-
3131 [ InlineData ( RsaSize . R2048 ) ]
3232 [ InlineData ( RsaSize . R3072 ) ]
3333 [ InlineData ( RsaSize . R4096 ) ]
@@ -43,6 +43,23 @@ public void Rsa_Encrypt_Success_Test(RsaSize size)
4343 Assert . NotEmpty ( encrypted ) ;
4444 }
4545
46+ [ Theory ( DisplayName = "Rsa encrypt with custom RSAEncryptionPadding" ) ]
47+ [ InlineData ( RsaSize . R2048 ) ]
48+ [ InlineData ( RsaSize . R3072 ) ]
49+ [ InlineData ( RsaSize . R4096 ) ]
50+ public void Rsa_Encrypt_WithPadding_Test ( RsaSize size )
51+ {
52+ var rsaKey = EncryptProvider . CreateRsaKey ( size ) ;
53+ var srcString = "rsa encrypt" ;
54+
55+ //Act
56+ var encrypted = EncryptProvider . RSAEncrypt ( rsaKey . PublicKey , srcString , RSAEncryptionPadding . OaepSHA512 ) ;
57+
58+ //Assert
59+ Assert . NotEmpty ( encrypted ) ;
60+ }
61+
62+
4663 [ Fact ( DisplayName = "Rsa encrypt fail with emtpy key" ) ]
4764 public void Rsa_Encrypt_EmptyKey_Test ( )
4865 {
@@ -82,6 +99,28 @@ public void Rsa_Decrypt_Success_Test(RsaSize size)
8299 Assert . Equal ( srcString , decrypted ) ;
83100 }
84101
102+
103+ [ Theory ( DisplayName = "Rsa decrypt with custom RSAEncryptionPadding" ) ]
104+ [ InlineData ( RsaSize . R2048 ) ]
105+ [ InlineData ( RsaSize . R3072 ) ]
106+ [ InlineData ( RsaSize . R4096 ) ]
107+ public void Rsa_Decrypt_WithPadding_Test ( RsaSize size )
108+ {
109+ var rsaKey = EncryptProvider . CreateRsaKey ( size ) ;
110+ var srcString = "rsa decrypt" ;
111+
112+ //Act
113+ var padding = RSAEncryptionPadding . OaepSHA512 ;
114+ var encrypted = EncryptProvider . RSAEncrypt ( rsaKey . PublicKey , srcString , padding ) ;
115+ var decrypted = EncryptProvider . RSADecrypt ( rsaKey . PrivateKey , encrypted , padding ) ;
116+
117+ //Assert
118+ Assert . NotEmpty ( encrypted ) ;
119+ Assert . NotEmpty ( decrypted ) ;
120+ Assert . Equal ( srcString , decrypted ) ;
121+ }
122+
123+
85124 [ Fact ( DisplayName = "Rsa decrypt fail with emtpy key" ) ]
86125 public void Rsa_Decrypt_EmptyKey_Test ( )
87126 {
0 commit comments