Exemplo n.º 1
0
 /// <summary>
 /// RSA签名验证
 /// </summary>
 /// <param name="strKeyPublic">公钥</param>
 /// <param name="strHashbyteDeformatter">Hash描述</param>
 /// <param name="strDeformatterData">签名后的结果</param>
 /// <returns></returns>
 public static bool SignatureDeformatter(string strKeyPublic, string data, string sign)
 {
     try
     {
         byte[] DeformatterData;
         byte[] HashbyteDeformatter;
         SHA1   md = SHA1.Create();
         HashbyteDeformatter = md.ComputeHash(Encoding.UTF8.GetBytes(data));
         DeformatterData     = Convert.FromBase64String(sign);
         RSACryptoServiceProvider     RSA            = RSACryptoService.CreateRsaProviderFromPublicKey(strKeyPublic);
         RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(RSA);
         //指定解密的时候HASH算法为MD5
         RSADeformatter.SetHashAlgorithm("SHA1");
         if (RSADeformatter.VerifySignature(HashbyteDeformatter, DeformatterData))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 2
0
        public static bool Verify(string PublicKey, string data, string Signature)
        {
            byte[] sign_byte             = Convert.FromBase64String(Signature);
            byte[] data_byte             = Encoding.UTF8.GetBytes(data);
            RSACryptoServiceProvider rsa = RSACryptoService.CreateRsaProviderFromPublicKey(PublicKey);

            //返回数据验证结果
            return(rsa.VerifyData(data_byte, "SHA1", sign_byte));
        }