コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }