Example #1
0
        /// <summary>
        /// 签名
        /// </summary>
        /// <param name="content">需要签名的内容</param>
        /// <param name="privateKey">私钥</param>
        /// <param name="inputCharset">编码格式</param>
        /// <returns>返回签名字符串</returns>
        public static string Sign(string content, string privateKey, string inputCharset)
        {
            Encoding code = Encoding.GetEncoding(inputCharset);

            byte[] data = code.GetBytes(content);
            RSACryptoServiceProvider rsa = RSAProviderFactory.DecodePemPrivateKey(privateKey);
            SHA1 sh = new SHA1CryptoServiceProvider();

            byte[] signData = rsa.SignData(data, sh);
            return(Convert.ToBase64String(signData));
        }
Example #2
0
        public static string Decrypt(byte[] data, string privateKey, string inputCharset)
        {
            string result = "";
            RSACryptoServiceProvider rsa = RSAProviderFactory.DecodePemPrivateKey(privateKey);
            SHA1 sh = new SHA1CryptoServiceProvider();

            byte[]   source = rsa.Decrypt(data, false);
            Encoding code   = Encoding.GetEncoding(inputCharset);

            char[] asciiChars = new char[code.GetCharCount(source, 0, source.Length)];
            code.GetChars(source, 0, source.Length, asciiChars, 0);
            result = new string(asciiChars);
            return(result);
        }