File tree 2 files changed +18
-4
lines changed
test/NETCore.Encrypt.Tests
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -819,21 +819,29 @@ public static RSAKey CreateRsaKey(RsaSize rsaSize = RsaSize.R2048)
819
819
/// Create an RSA key
820
820
/// </summary>
821
821
/// <param name="rsa">rsa</param>
822
+ /// <param name="includePrivate"></param>
822
823
/// <returns></returns>
823
- public static RSAKey CreateRsaKey ( RSA rsa )
824
+ public static RSAKey CreateRsaKey ( RSA rsa , bool includePrivate = true )
824
825
{
825
826
Check . Argument . IsNotNull ( rsa , nameof ( rsa ) ) ;
826
827
827
828
string publicKey = rsa . ToJsonString ( false ) ;
828
- string privateKey = rsa . ToJsonString ( true ) ;
829
829
830
- return new RSAKey ( )
830
+
831
+ var rsaKey = new RSAKey ( )
831
832
{
832
833
PublicKey = publicKey ,
833
- PrivateKey = privateKey ,
834
+
834
835
Exponent = rsa . ExportParameters ( false ) . Exponent . ToHexString ( ) ,
835
836
Modulus = rsa . ExportParameters ( false ) . Modulus . ToHexString ( )
836
837
} ;
838
+
839
+ if ( includePrivate )
840
+ {
841
+ string privateKey = rsa . ToJsonString ( true ) ;
842
+ rsaKey . PrivateKey = privateKey ;
843
+ }
844
+ return rsaKey ;
837
845
}
838
846
839
847
/// <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