Example #1
0
 public static XmlElement Generate(XmlElement xmlElement, string elementId, AsymmetricAlgorithm signingKey, KeyInfo keyInfo, SignedXml signedXml, string inclusiveNamespacesPrefixList, string digestMethod, string signatureMethod)
 {
     try
     {
         XmlSignature.RemoveSignature(xmlElement);
         signedXml.SigningKey = signingKey;
         signedXml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2001/10/xml-exc-c14n#";
         Reference reference = new Reference();
         reference.Uri = "#" + elementId;
         reference.AddTransform((Transform) new XmlDsigEnvelopedSignatureTransform());
         if (!string.IsNullOrEmpty(digestMethod))
         {
             reference.DigestMethod = digestMethod;
         }
         XmlDsigExcC14NTransform excC14Ntransform = new XmlDsigExcC14NTransform();
         //if (!string.IsNullOrEmpty(inclusiveNamespacesPrefixList))
         //    excC14Ntransform.InclusiveNamespacesPrefixList = inclusiveNamespacesPrefixList;
         reference.AddTransform((Transform)excC14Ntransform);
         signedXml.AddReference(reference);
         signedXml.KeyInfo = keyInfo;
         if (!string.IsNullOrEmpty(signatureMethod))
         {
             signedXml.SignedInfo.SignatureMethod = signatureMethod;
         }
         signedXml.ComputeSignature();
         return(signedXml.GetXml());
     }
     catch (Exception ex)
     {
         throw new SamlSignatureException("Failed to generate XML signature.", ex);
     }
 }
 public static void RemoveSignature(XmlElement xmlElement)
 {
     XmlSignature.RemoveSignature(xmlElement);
 }