、あなたはこのように、.pfxファイルからあなたX509証明書を取得する場合:
X509Certificate2 certificate = new X509Certificate2(certFile, pfxPassword);
RSACryptoServiceProvider rsaCsp = (RSACryptoServiceProvider) certificate.PrivateKey;
が次にあなたがそうのように、公開キー部分をエクスポートすることができます。
rsaCsp.ToXmlString(false);
を」偽 "の部分は、公共の部分をエクスポートするだけで、プライベートな部分をエクスポートしないと言う。 (RSA.ToXmlString用DOC)の検証アプリケーションで
そして、
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
csp.FromXmlString(PublicKeyXml);
bool isValid = VerifyXml(xmlDoc, rsa2);
を使用し、VerifyXmlがCheckSignature()
を呼び出します。
private Boolean VerifyXml(XmlDocument Doc, RSA Key)
{
// Create a new SignedXml object and pass it
// the XML document class.
var signedXml = new System.Security.Cryptography.Xml.SignedXml(Doc);
// Find the "Signature" node and create a new XmlNodeList object.
XmlNodeList nodeList = Doc.GetElementsByTagName("Signature");
// Throw an exception if no signature was found.
if (nodeList.Count <= 0)
{
throw new CryptographicException("Verification failed: No Signature was found in the document.");
}
// Though it is possible to have multiple signatures on
// an XML document, this app only supports one signature for
// the entire XML document. Throw an exception
// if more than one signature was found.
if (nodeList.Count >= 2)
{
throw new CryptographicException("Verification failed: More that one signature was found for the document.");
}
// Load the first <signature> node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// Check the signature and return the result.
return signedXml.CheckSignature(Key);
}
ありがとう、それは私がはっきりとわからなかったものです。 "署名者"証明書を取得し、 "検証者"として.cerファイルを使用するには、X509Storeの証明書を使用する必要があることがわかりました。 – willvv