I am facing an issue and cannot figure out what i am missing.I am calculating a digital signature in c# and cannot get the right signature value.Does anybody know if signature prefix can change the signature value? My webservice wants a "ds" prefix and what
i do fom code is to calculate the signature and after that add the prefix.Could this be the problem? My digest value is the right one but the signature value is different.Is it necessary to first set the prefix and after that calculate the signature? Thanks!
adrianrpd20
Member
1 Points
18 Posts
xmld digital signature
Feb 27, 2013 09:51 AM|LINK
I am facing an issue and cannot figure out what i am missing.I am calculating a digital signature in c# and cannot get the right signature value.Does anybody know if signature prefix can change the signature value? My webservice wants a "ds" prefix and what i do fom code is to calculate the signature and after that add the prefix.Could this be the problem? My digest value is the right one but the signature value is different.Is it necessary to first set the prefix and after that calculate the signature? Thanks!
Pengzhen Son...
Star
8189 Points
842 Posts
Microsoft
Re: xmld digital signature
Feb 28, 2013 01:35 AM|LINK
HI,
Try this about setprefix
private void SetPrefix(String prefix, XmlNode node) { foreach (XmlNode n in node.ChildNodes) { SetPrefix(prefix, n); n.Prefix = prefix; } }For detailed information, you can refer here
http://stackoverflow.com/questions/12219232/xml-signature-ds-prefix
http://stackoverflow.com/questions/381517/net-signed-xml-prefix
Hope it can help you.
Feedback to us
Develop and promote your apps in Windows Store
adrianrpd20
Member
1 Points
18 Posts
Re: xmld digital signature
Mar 04, 2013 09:04 AM|LINK
Thanks!
Still not able to figure this out.
I think that setprefix function can set the prefix after calculating the signature ....and i need it before to each tag from signedInfo.
Altough i am not sure how i can do this .
Here is my code.I need to set the prefix before calling compute signature i think.
SignedXmlWithId signedXml = new SignedXmlWithId(xmldoc);
signedXml.SignedInfo.SignatureMethod = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
XmlDsigExcC14NTransform canMethod = (XmlDsigExcC14NTransform)signedXml.SignedInfo.CanonicalizationMethodObject;
canMethod.InclusiveNamespacesPrefixList = "idp soapenv spg";
// signedXml.KeyInfo.AddClause(new System.Security.Cryptography.Xml.KeyInfoX509Data(cer));
Reference tRef = new Reference("#id-20");
// XmlDsigEnvelopedSignatureTransform env1 = new XmlDsigEnvelopedSignatureTransform();
// XmlDsigExcC14NWithCommentsTransform env1 = new XmlDsigExcC14NWithCommentsTransform();
XmlDsigExcC14NTransform env = new XmlDsigExcC14NTransform("idp spg");
env.Algorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
tRef.DigestMethod = "http://www.w3.org/2000/09/xmldsig#sha1";
tRef.AddTransform(env);
signedXml.AddReference(tRef);
signedXml.SigningKey = cer.PrivateKey;
signedXml.ComputeSignature();
XmlElement xmlDsig = signedXml.GetXml();
xmlDsig.SetAttribute("Id", "Signature-5");