Exemplo n.º 1
0
        public static void RsaSignTest()
        {
            string privateKey    = string.Empty;
            string publicKey     = string.Empty;
            string privateKeyPk8 = string.Empty;

            // 生成密钥对
            RsaKeyHelper.GenKey(out publicKey, out privateKey, out privateKeyPk8);

            string data       = @"Hello 中国,这是一段很神奇的代码";
            string signedData = RsaBCHelper.Sign(data, privateKey);
            bool   success    = RsaBCHelper.Verify(data, signedData, publicKey);

            Console.WriteLine("原文:{0}", data);
            Console.WriteLine("签名:{0}", signedData);
            Console.WriteLine("验签:{0}", success);
        }
Exemplo n.º 2
0
        public static void RsaTest()
        {
            string privateKey    = string.Empty;
            string publicKey     = string.Empty;
            string privateKeyPk8 = string.Empty;

            // 生成密钥对
            RsaKeyHelper.GenKey(out publicKey, out privateKey, out privateKeyPk8);

            string data    = @"Hello 中国,这是一段很神奇的代码";
            string encData = RsaBCHelper.Encrypt(data, publicKey);
            string decData = RsaBCHelper.Decrypt(encData, privateKey);

            Console.WriteLine("原文:{0}", data);
            Console.WriteLine("密文:{0}", encData);
            Console.WriteLine("解密:{0}", decData);
        }