0

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);
john.kernel
  • 332
  • 3
  • 16
  • See my solution at following posting : https://stackoverflow.com/questions/46722997/saml-assertion-in-a-xml-using-c-sharp/46724392 – jdweng Jan 22 '18 at 11:53
  • Even with this solution I cant obtain the values like wsu:id, SignarureId etc. – john.kernel Jan 22 '18 at 12:15
  • It is a namespace issue. That is why I used [string soap = "....."] and then loaded using doc.LoadXml(soap); I also include namespace in the doc.GetElementsByTagName("wsse:Security") – jdweng Jan 22 '18 at 12:25

0 Answers0