简体   繁体   English

替换分离的XML签名(.NET)中的文件引用

[英]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. 我需要使用分离的签名对一些XML文档进行签名,然后通过电子邮件将其发送给某人,以便他以后可以验证签名。 My problems is, the reference to the signed files is an URI and only takes absolute path and filenames. 我的问题是,对签名文件的引用是一个URI,并且仅使用绝对路径和文件名。 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. 只是不起作用,因为它不是有效的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 预先感谢,Guenther

Change current working dir to XML file location: 将当前工作目录更改为XML文件位置:

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

You can also write own XmlResolver 您也可以编写自己的XmlResolver

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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