I have trouble with soap api. I have to sign Xml, everything goes well but my signature is still invalid. While testing this Api with SoapUI everything is all right. Main problem is that some elements are missing like `
wsu:id, KeyInfo id,SignatureId and Reference URI
All those elements are the same except four last numbers(in soapUI). I know that they are KeyInfo elements but inside my signatures those values are null.
This is how I sign my xml:
//Create new instance of SignedXml then load the document into it
SignedXml signedXml = new SignedXml(xmlDoc);
signedXml.SigningKey =cert.PrivateKey;
//According to SoapUi Signature Algorithm must be rsa-sha1
signedXml.SignedInfo.SignatureMethod = SignedXml.XmlDsigRSASHA1Url;
//According to SoapUi Canonization method must be xml-exc-c14n
signedXml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
//KeyInfo
KeyInfo keyInfo = new KeyInfo();
KeyInfoX509Data keyInfoData = new KeyInfoX509Data(cert);
keyInfo.AddClause(keyInfoData);
signedXml.KeyInfo = keyInfo;
//Reference
Reference reference = new Reference("");
reference.AddTransform(new XmlDsigC14NTransform());
//Signature
Signature XmlSignature = signedXml.Signature;
XmlSignature.SignedInfo.AddReference(reference);
signedXml.ComputeSignature();
Do I need to add some transforms to reference ? Like in this solution?
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
XmlDsigExcC14NTransform c14n = new XmlDsigExcC14NTransform();
reference.AddTransform(env);
reference.AddTransform(c14n);