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)
841841 /// Create an RSA key
842842 /// </summary>
843843 /// <param name="rsa">rsa</param>
844+ /// <param name="includePrivate"></param>
844845 /// <returns></returns>
845- public static RSAKey CreateRsaKey ( RSA rsa )
846+ public static RSAKey CreateRsaKey ( RSA rsa , bool includePrivate = true )
846847 {
847848 Check . Argument . IsNotNull ( rsa , nameof ( rsa ) ) ;
848849
849850 string publicKey = rsa . ToJsonString ( false ) ;
850- string privateKey = rsa . ToJsonString ( true ) ;
851851
852- return new RSAKey ( )
852+
853+ var rsaKey = new RSAKey ( )
853854 {
854855 PublicKey = publicKey ,
855- PrivateKey = privateKey ,
856+
856857 Exponent = rsa . ExportParameters ( false ) . Exponent . ToHexString ( ) ,
857858 Modulus = rsa . ExportParameters ( false ) . Modulus . ToHexString ( )
858859 } ;
860+
861+ if ( includePrivate )
862+ {
863+ string privateKey = rsa . ToJsonString ( true ) ;
864+ rsaKey . PrivateKey = privateKey ;
865+ }
866+ return rsaKey ;
859867 }
860868
861869 /// <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