File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
test/NETCore.Encrypt.Tests Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -841,21 +841,29 @@ public static RSAKey CreateRsaKey(RsaSize rsaSize = RsaSize.R2048)
841
841
/// Create an RSA key
842
842
/// </summary>
843
843
/// <param name="rsa">rsa</param>
844
+ /// <param name="includePrivate"></param>
844
845
/// <returns></returns>
845
- public static RSAKey CreateRsaKey ( RSA rsa )
846
+ public static RSAKey CreateRsaKey ( RSA rsa , bool includePrivate = true )
846
847
{
847
848
Check . Argument . IsNotNull ( rsa , nameof ( rsa ) ) ;
848
849
849
850
string publicKey = rsa . ToJsonString ( false ) ;
850
- string privateKey = rsa . ToJsonString ( true ) ;
851
851
852
- return new RSAKey ( )
852
+
853
+ var rsaKey = new RSAKey ( )
853
854
{
854
855
PublicKey = publicKey ,
855
- PrivateKey = privateKey ,
856
+
856
857
Exponent = rsa . ExportParameters ( false ) . Exponent . ToHexString ( ) ,
857
858
Modulus = rsa . ExportParameters ( false ) . Modulus . ToHexString ( )
858
859
} ;
860
+
861
+ if ( includePrivate )
862
+ {
863
+ string privateKey = rsa . ToJsonString ( true ) ;
864
+ rsaKey . PrivateKey = privateKey ;
865
+ }
866
+ return rsaKey ;
859
867
}
860
868
861
869
/// <summary>
Original file line number Diff line number Diff line change @@ -309,6 +309,12 @@ public void Rsa_From_Pem_Test()
309
309
Assert . NotNull ( rsaFromPublickPem ) ;
310
310
Assert . NotNull ( rsaFromPublickPem ) ;
311
311
Assert . Equal ( rsaFromPublickPem . KeySize , rsaFromPrivatePem . KeySize ) ;
312
+ var privateKey = EncryptProvider . CreateRsaKey ( rsaFromPrivatePem ) ;
313
+ var publicKey = EncryptProvider . CreateRsaKey ( rsaFromPublickPem , false ) ;
314
+ var raw = "123123124" ;
315
+ var signStr = EncryptProvider . RSASign ( raw , privateKey . PrivateKey ) ;
316
+ var result = EncryptProvider . RSAVerify ( raw , signStr , publicKey . PublicKey ) ;
317
+ Assert . True ( result ) ;
312
318
}
313
319
314
320
You can’t perform that action at this time.
0 commit comments