C# RSA。验证.Net Core 3.0中的问题

C# RSA。验证.Net Core 3.0中的问题,c#,encryption,.net-core,C#,Encryption,.net Core,我正在与第三方合作,他们通过字节数组向我发送证书。他们在XML文档中向我发送3个字符串,包括x509Data、SignatureValue和DigestValue(用于调试) 他们希望我使用x509Data证书中包含的证书公钥验证SignatureValue是否有效。我正在填充证书,但当我尝试验证时,它总是返回false 这是我的密码: byte[] SignatureValueBytes = Convert.FromBase64String(Signature.SignatureValue);

我正在与第三方合作,他们通过字节数组向我发送证书。他们在XML文档中向我发送3个字符串,包括x509Data、SignatureValue和DigestValue(用于调试)

他们希望我使用x509Data证书中包含的证书公钥验证SignatureValue是否有效。我正在填充证书,但当我尝试验证时,它总是返回false

这是我的密码:

byte[] SignatureValueBytes = Convert.FromBase64String(Signature.SignatureValue);
byte[] x509DataBytes = Convert.FromBase64String(Signature.x509Data);
byte[] DigestValueBytes = Convert.FromBase64String(Signature.DigestValue);
X509Certificate2 cert = new X509Certificate2(x509DataBytes);
using (RSA RSA = (RSA)cert.PublicKey.Key)
{
    bool a = RSA.VerifyData(x509DataBytes, SignatureValueBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}

Signature.*是来自XML文件的字符串。一些善良的灵魂能指出我哪里出了问题吗?

您的代码,正如所写的,正在尝试验证
SignatureValueBytes
是使用RSASSA-PKCS1-SHA256对
x509DataBytes
进行签名的签名

假设RSASSA-PKCS1-SHA256部分正确,您可能希望使用
VerifyHash
DigestValueBytes
而不是
VerifyData
x509DataBytes
。(您还希望使用
cert.GetRSAPublicKey()
而不是
cert.PublicKey.Key


空格和换行符重要吗?在我的XML SignatureValue中是多行的,也是多行的吗?
byte[] SignatureValueBytes = Convert.FromBase64String(Signature.SignatureValue);
byte[] x509DataBytes = Convert.FromBase64String(Signature.x509Data);
byte[] DigestValueBytes = Convert.FromBase64String(Signature.DigestValue);
X509Certificate2 cert = new X509Certificate2(x509DataBytes);
using (RSA RSA = cert.GetRSAPublicKey())
{
    bool a = RSA.VerifyHash(DigestValueBytes, SignatureValueBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}