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 @@ -819,21 +819,29 @@ public static RSAKey CreateRsaKey(RsaSize rsaSize = RsaSize.R2048)
819819 /// Create an RSA key
820820 /// </summary>
821821 /// <param name="rsa">rsa</param>
822+ /// <param name="includePrivate"></param>
822823 /// <returns></returns>
823- public static RSAKey CreateRsaKey ( RSA rsa )
824+ public static RSAKey CreateRsaKey ( RSA rsa , bool includePrivate = true )
824825 {
825826 Check . Argument . IsNotNull ( rsa , nameof ( rsa ) ) ;
826827
827828 string publicKey = rsa . ToJsonString ( false ) ;
828- string privateKey = rsa . ToJsonString ( true ) ;
829829
830- return new RSAKey ( )
830+
831+ var rsaKey = new RSAKey ( )
831832 {
832833 PublicKey = publicKey ,
833- PrivateKey = privateKey ,
834+
834835 Exponent = rsa . ExportParameters ( false ) . Exponent . ToHexString ( ) ,
835836 Modulus = rsa . ExportParameters ( false ) . Modulus . ToHexString ( )
836837 } ;
838+
839+ if ( includePrivate )
840+ {
841+ string privateKey = rsa . ToJsonString ( true ) ;
842+ rsaKey . PrivateKey = privateKey ;
843+ }
844+ return rsaKey ;
837845 }
838846
839847 /// <summary>
Original file line number Diff line number Diff line change @@ -309,6 +309,12 @@ public void Rsa_From_Pem_Test()
309309 Assert . NotNull ( rsaFromPublickPem ) ;
310310 Assert . NotNull ( rsaFromPublickPem ) ;
311311 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 ) ;
312318 }
313319
314320
You can’t perform that action at this time.
0 commit comments