在C#中签署XML并使用XMLsignature设置签名位置

时间:2018-08-01 13:47:28

标签: c# xml x509 sign xml-signature

我有一些代码可以用x509证书签名xml。

代码在下面。问题有时是,我不知道为什么,签名位于文件末尾(这是正确的),有时位于中间(这是错误的)。

如何强制将其放置在文件末尾?

string certID = Configuration["Signature:certID"];
string delegated_domain = Configuration["Signature:delegated_domain"];
string delegated_password = Configuration["Signature:delegated_password"];
string delegated_user = Configuration["Signature:delegated_user"];
string typeOtpAuth = Configuration["Signature:typeOtpAuth"];
string user = Configuration["Signature:user"];
string otpPwd = Configuration["Signature:otpPwd"];
string host = Configuration["Signature:host"];
XMLsignature xmlSign = new XMLsignature(certID, delegated_domain, delegated_password, delegated_user, typeOtpAuth, user, otpPwd, host);

var text = System.IO.File.ReadAllText(fullpath);

var t64 = Utility.EncodeStringToBase64(text);

var signed = await xmlSign.SignXML(t64);
var fileBytes = Convert.FromBase64String(signed);

string xml = Encoding.UTF8.GetString(fileBytes);
System.IO.File.WriteAllText(fullpath, xml);

0 个答案:

没有答案