问题
I've been developing this console application for about close to 2-3 months now.
What I'm trying to achieve from the console application is to generate data files and sign the files into a "signature.xml" file. It is working using several custom methods to sign (without use of Regedit Key).
However, once the number of references goes over 99, it refuses to sign and gives the error "Malformed SignedInfo/Reference..". Even though previously it did work and this error has never surfaced.
I've tried googling and searching for solutions, but to no avail for signing more than XX amount of references. Note that there is no syntax error or typo in the signature file, it is generated exactly the same as it was when it is under 100 file references.
There is also no bad hash of files generated, so I really have no idea what went wrong. No exceptions caught when retrieving the hash and file paths of the generated files that are to be signed.
I hope the community here will be able to help :(
Snippet of the code:
private static byte[] GetC14NDigest(XmlDocument xmlDocument, HashAlgorithm hash)
{
try
{
byte[] digestedSignedInfo;
XmlDocument containingDocument = xmlDocument;
XmlElement context = xmlDocument.DocumentElement;
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
SignedXml signedXml = new SignedXml();
signedXml.LoadXml((XmlElement)nodeList[0]);
string baseUri = (containingDocument == null ? null : containingDocument.BaseURI);
XmlResolver resolver = new XmlSecureResolver(new XmlUrlResolver(), baseUri);
XmlDocument doc = PreProcessElementInput(signedXml.SignedInfo.GetXml(), revolver, baseUri);
Transform c14nMethodTransform = signedXml.SignedInfo.CanonicalizationMethodObject;
digestedSignedInfo = c14nMethodTransform.GetDigestedOutput(hash);
return digestedSignedInfo;
}
catch(Exception ex)
{
Log.LogText(ex.Message);
Log.LogText(ex.StackTrace);
return null;
}
}
来源:https://stackoverflow.com/questions/60541242/signedxml-loadxmlxmlelementnodelist0-returns-malformed-signedinfo-referen