我有一个对我的 xml 文件进行签名的函数,该文件采用 utf-8 编码,但是当我应用该符号时,它显示“utf-8 with Boom”(错误版本),我如何正确保存文件
private static void FirmarDocumentoComplemento(string pathXmlDocument, string pathCert, string passCert, string pathXmlSignet, string ruta, string rut, string fecha, string tipo)
{
XmlDocument documentXml = new XmlDocument();
documentXml.Load(pathXmlDocument);
SignedXml firmado = new SignedXml(documentXml);
var cert = RSA_helper.GetX509Certificate(pathCert, passCert);
firmado.SigningKey = (RSA)cert.PrivateKey;
firmado.SignedInfo.SignatureMethod = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
//digest info
Reference reference = new Reference();
reference.Uri = "";
reference.DigestMethod = "http://www.w3.org/2000/09/xmldsig#sha1";
firmado.AddReference(reference);
// with the public key will be added in the signature part.
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue((RSA)cert.PrivateKey));
keyInfo.AddClause(new KeyInfoX509Data(cert));
firmado.KeyInfo = keyInfo;
firmado.ComputeSignature();
XmlElement xmlDigitalSignature = firmado.GetXml();
// buscamos el ultimo elemento del documento para agregarle la firma
XmlElement elemento = (XmlElement)documentXml.SelectSingleNode(@"//datos_complementarios_declaracion_ingreso/representantes[last()]");
XmlNode parent = elemento.ParentNode;
parent.InsertAfter(xmlDigitalSignature, elemento);
string ruta_completa = ruta + rut + " - " + tipo + " - " + fecha + " - N - " + "Complemento Firmado.xml";
documentXml.Save(ruta_completa);
}
PIPIONE
相关分类