使用数字签名签署XML

时间:2016-08-08 13:10:46

标签: c# xml digital-signature signing

我正在使用一些网络服务,该服务要求通过HTTP post请求发布经过数字签名的XML 他们只给了我一个文件(key.dat),我应该将它应用于我的XML 我该怎么办?

1 个答案:

答案 0 :(得分:0)

您可以查看here

private static XmlElement GetXmlDigitalSignature(XmlDocument x, AsymmetricAlgorithm key)
{
    var signedXml = new SignedXml(x) { SigningKey = key };
    var reference = new Reference { Uri = "", TransformChain = new TransformChain(), };

    reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());

    signedXml.AddReference(reference);
    signedXml.ComputeSignature();

    return signedXml.GetXml();
}

var signature = GetXmlDigitalSignature(xmlDocument, algorithm);
xmlDocument.FirstChild.AppendChild(xmlDocument.ImportNode(signature, true));