예제 #1
0
        public static void TestAsymmetricSign1()
        {
            var text = "非对称签名测试1";

            Console.WriteLine(text);

            var cipher = new AsymmetricCipher(AsymmetricAlgorithm.Rsa);

            Console.WriteLine("=====================publicKey================");
            Console.WriteLine(cipher.Base64PublicKey);
            Console.WriteLine();

            Console.WriteLine("=====================privateKey================");
            Console.WriteLine(cipher.Base64PrivateKey);
            Console.WriteLine();

            var data = Encoding.UTF8.GetBytes(text);
            var sign = cipher.Sign(data);

            Console.WriteLine($"sign:{Convert.ToBase64String(sign)}");

            var verify = cipher.Verify(data, sign);

            Console.WriteLine($"verify:{verify}");
        }
예제 #2
0
        public static void TestAsymmetricSign2()
        {
            var text = "非对称签名测试2";

            Console.WriteLine(text);

            var publicKey =
                "MIIBtzCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9EAMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdrmVClpJ+f6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXzrith1yrv8iIDGZ3RSAHHAhUAl2BQjxUjC8yykrmCouuEC/BYHPUCgYEA9+GghdabPd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoDgYQAAoGABmpaSji+l7CBZ9a3wtEHMWwpCUnZy66wGAff5fZuAHpPRB64ljSn0OAcBwhHBcjVBKvP+XUDExkACvAm//oz0bpbPzUeslw2yIELJDRr0oXFZCbJpPZWUBw9v4CiiWUBMoDMggjXQ8MNcLrZkOXK8q/jEJbLXrApFQb1AOmLf4g=";
            var privateKey =
                "MIIBSwIBADCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9EAMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdrmVClpJ+f6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXzrith1yrv8iIDGZ3RSAHHAhUAl2BQjxUjC8yykrmCouuEC/BYHPUCgYEA9+GghdabPd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoEFgIUDzw/Nh7Wa4Wg4NnquitP0NgQ1+0=";

            var cipher = new AsymmetricCipher(AsymmetricAlgorithm.Dsa, publicKey, privateKey);

            var data      = Encoding.UTF8.GetBytes(text);
            var signature = cipher.Sign(data);

            Console.WriteLine($"signature:{Convert.ToBase64String(signature)}");

            signature = Convert.FromBase64String("MCwCFGSjitt2rP7A8p3mcFmjjkuvAsCUAhQvlzprmCWVqEbLrs928Kl2QA2h2g==");

            var verification = cipher.Verify(data, signature);

            Console.WriteLine($"verification:{verification}");
        }