我收到了一个XML文件
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Envelope>
<OrgContent>
</OrgContent>
<Signature>
Y7z1Y+c+u80a9vhUSi`....`
`......`u80a9vhUSi==
</Signature>
<Certificate>
MIIExjCCA66gAwIBAgIJNv5`.......`
`.....`66gAwIBAgIJNv5=
</Certificate>
</Envelope>
我将<signature>
传递给签名数据,将<certificate>
值传递给pubkey后转换为byte [] array..to以下函数..
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
并且没有验证签名..(签名有效)。任何人都可以告诉这段代码有什么问题.. ???