1

我收到了一个 XML 文件

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 <Envelope>

   <OrgContent>
   </OrgContent>

   <Signature>
     Y7z1Y+c+u80a9vhUSi`....`
     `......`u80a9vhUSi==
   </Signature>

   <Certificate>
     MIIExjCCA66gAwIBAgIJNv5`.......`
     `.....`66gAwIBAgIJNv5=
   </Certificate>

</Envelope>

我在转换为 byte[] 数组后传递<signature>给签名数据、<certificate>值到 pubkey.. 到以下函数..

static bool Verify(byte[] signature, byte[] pubKeyBytes)
{
   RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
   RSAParameters RSAKeyInfo = RSA.ExportParameters(false);
   RSAKeyInfo.Modulus = pubKeyBytes;
   RSA.ImportParameters(RSAKeyInfo);
   // Hash the data
   SHA1Managed sha1 = new SHA1Managed();
   UnicodeEncoding encoding = new UnicodeEncoding();
   // byte[] data = encoding.GetBytes(text);
   byte[] hash = sha1.ComputeHash(base64Decode());

   // Verify the signature with the hash
   return RSA.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA1"), signature);
}

base64Decode()方法返回转换成的原始内容byte[]

我没有收到任何错误,但仍然......verify()方法正在返回false并且没有验证签名......(签名有效)。谁能告诉这段代码有什么问题..???

4

0 回答 0