Exemple #1
0
        /// <summary>
        /// 验签
        /// </summary>
        /// <param name="data">签名前的数据</param>
        /// <param name="publickey">公钥</param>
        /// <param name="sign">签名</param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public static bool rsaCheck(string data, string publickey, string sign, string encoding = "UTF-8")
        {
            byte[]  bt  = Encoding.GetEncoding(encoding).GetBytes(data);
            byte[]  bt2 = Convert.FromBase64String(sign);
            RSA_PEM pem = RSA_PEM.FromPEM(publickey);

            using (RSACryptoServiceProvider provider = pem.GetRSA())
            {
                return(provider.VerifyData(bt, CryptoConfig.MapNameToOID("SHA256"), bt2));
            }
        }
Exemple #2
0
        /// <summary>
        /// 签名
        /// </summary>
        /// <param name="str">需签名的数据</param>
        /// <param name="privateKey">私钥</param>
        /// <param name="encoding">编码格式 默认utf-8</param>
        /// <returns></returns>
        public static string Signature(string str, string privateKey, string encoding = "UTF-8")
        {
            byte[]  bt  = Encoding.GetEncoding(encoding).GetBytes(str);
            RSA_PEM pem = RSA_PEM.FromPEM(privateKey);

            using (RSACryptoServiceProvider provider = pem.GetRSA())
            {
                byte[] inArray = provider.SignData(bt, CryptoConfig.MapNameToOID("SHA256"));
                string sign    = Convert.ToBase64String(inArray);
                return(sign);
            }
        }