public void Test_SHA1withRSA_Sign_Verify() { string content = @"Hello World"; byte[] buffer = Encoding.UTF8.GetBytes(content); string signature = SHA1withRSA.Sign(RSAPrivateKeyXmlString, buffer); bool verified = SHA1withRSA.Verify(RSAPublicKeyXmlString, buffer, signature); Assert.IsTrue(verified); }
public static bool Test_SHA1withRSA_Sign_Verify_With_DotNet( string privateKeyXmlString, string publicKeyXmlString) { string content = @"Hello World"; byte[] buffer = Encoding.UTF8.GetBytes(content); string signature = SHA1withRSA.Sign(privateKeyXmlString, buffer); bool verified = SHA1withRSA.Verify(publicKeyXmlString, buffer, signature); return(verified); }
public static bool Test_SHA1withRSA_Sign_With_BouncyCastle_Then_Verify_With_DotNet( RsaPrivateCrtKeyParameters rsaPrivate, string publicKeyXmlString) { string content = @"Hello World"; byte[] buffer = Encoding.UTF8.GetBytes(content); var signer = SignerUtilities.GetSigner(@"SHA-1withRSA"); signer.Init(true, rsaPrivate); signer.BlockUpdate(buffer, 0, buffer.Length); byte[] signedHash = signer.GenerateSignature(); string signature = Convert.ToBase64String(signedHash); bool verified = SHA1withRSA.Verify(publicKeyXmlString, buffer, signature); return(verified); }
public static bool Test_SHA1withRSA_Sign_With_DotNet_Then_Verify_With_BouncyCastle( string privateKeyXmlString, RsaKeyParameters rsaPublic) { string content = @"Hello World"; byte[] buffer = Encoding.UTF8.GetBytes(content); string signature = SHA1withRSA.Sign(privateKeyXmlString, buffer); var signer = SignerUtilities.GetSigner(@"SHA-1withRSA"); signer.Init(false, rsaPublic); signer.BlockUpdate(buffer, 0, buffer.Length); byte[] signedHash = Convert.FromBase64String(signature); bool verified = signer.VerifySignature(signedHash); return(verified); }