简体   繁体   中英

Replace file reference in detached XML signature (.NET)

I need to sign some XML documents with a detached signature and send them to someone via email so that he can verify the signatures later on. My problems is, the reference to the signed files is an URI and only takes absolute path and filenames. How can that be changed to only the filename? Beacsue, I cannot assure this files exists at the receiver in the exact same place. Something like

 reference.Uri = "file_to_sign.xml";

just won't work, because it's not a valid URI. Here's the code:

var signer = new SignedXml(xmlDoc);
signer.KeyInfo = new KeyInfo();
signer.KeyInfo.AddClause(new RSAKeyValue(key));
signer.SigningKey = key;

var reference = new Reference();
reference.Uri = "file://C:/data/path/file_to_sign.xml";
signer.AddReference(reference);
signer.ComputeSignature();

Thanks in advance, Guenther

Change current working dir to XML file location:

var current=Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(xml_file_directory);
//sign/verify with relative URIs references
Directory.SetCurrentDirectory(curent);

You can also write own XmlResolver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM