海关7月后的新加签方式C#和java版本代码展示
1.SignedInfo
string namespaceURI = "http://www.w3.org/2000/09/xmldsig#";
newChild = document.CreateElement("ds:Signature", namespaceURI);
element2 = document.CreateElement("ds:SignedInfo", namespaceURI);
element2.SetAttribute("xmlns:ceb", "http://www.chinaport.gov.cn/ceb");
element2.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
element3 = document.CreateElement("ds:CanonicalizationMethod", namespaceURI);
element3.AppendChild(document.CreateTextNode(""));
element4 = document.CreateElement("ds:SignatureMethod", namespaceURI);
element5 = document.CreateElement("ds:Reference", namespaceURI);
element6 = document.CreateElement("ds:Transforms", namespaceURI);
element7 = document.CreateElement("ds:Transform", namespaceURI);
element8 = document.CreateElement("ds:DigestMethod", namespaceURI);
element9 = document.CreateElement("ds:DigestValue", namespaceURI);
element10 = document.CreateElement("ds:SignatureValue", namespaceURI);
element11 = document.CreateElement("ds:KeyInfo", namespaceURI);
element12 = document.CreateElement("ds:KeyName", namespaceURI);
element13 = document.CreateElement("ds:X509Data", namespaceURI);
element14 = document.CreateElement("ds:X509Certificate", namespaceURI);
newChild.SetAttribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#");
element3.SetAttribute("Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
if (this.signType == "SM")
{
element4.SetAttribute("Algorithm", "http://www.chinaport.gov.cn/2022/04/xmldsig#sm2-sm3");
}
else
{
element4.SetAttribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
}
element5.SetAttribute("URI", "");
element7.SetAttribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#enveloped-signature");
element6.AppendChild(element7);
if (this.signType == "SM")
{
element8.SetAttribute("Algorithm", "http://www.chinaport.gov.cn/2022/04/xmldsig#sm3");
}
else
{
element8.SetAttribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1");
}
element5.AppendChild(element6);
element5.AppendChild(element8);
element9.AppendChild(document.CreateTextNode(this.digestValue));
element5.AppendChild(element9);
element2.AppendChild(element3);
element2.AppendChild(element4);
element2.AppendChild(element5);
element10.AppendChild(document.CreateTextNode(this.signatureValue));
element12.AppendChild(document.CreateTextNode(this.keyName));
element14.AppendChild(document.CreateTextNode(this.x509Certificate));
element13.AppendChild(element14);
element11.AppendChild(element12);
element11.AppendChild(element13);
newChild.AppendChild(element2);
newChild.AppendChild(element10);
newChild.AppendChild(element11);
document.AppendChild(newChild);
}
catch (Exception exception)
{
throw new Exception("产生SignatureXML报文时报错. Error=" + exception.Message);
}
outerXml = document.OuterXml;
2.java
版本
本文来自博客园,作者:跨境狮,转载请注明原文链接:https://www.cnblogs.com/cology/p/16668879.html
浙公网安备 33010602011771号