C# .NET - How To Put a Digital Signature on a SOAP message

Asked By Bradley Ward on 12-Oct-05 09:31 AM
Hello,
I need to digitally sign an outgoing SOAP message. I found a very good article by Peter Bromberg that got close to what I need (see http://www.eggheadcafe.com/articles/20021231.asp), but not quite. His article put a binary signature on the message.
I'm not totally sure what I need, but apparently it is not a binary signature because the example XML I've been provided is different than that produced by Peter's article. I need to produce something that looks like the XML shown below.
Can anyone give me more information on what sort of digital signature I am trying to do here, point me to any good online resources (especially sample code), or even just give me some good Google strings???
Any help would be much appreciated.
Thanks,
Brad
			<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
				<ds:SignedInfo>
					<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
					<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
					<ds:Reference URI="#body">
						<ds:Transforms>
							<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
						</ds:Transforms>
						<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
						<ds:DigestValue>d6xssQEvw9mMXEbQ1+/jpYTFbqY=</ds:DigestValue>
					</ds:Reference>
				</ds:SignedInfo>
	<ds:SignatureValue>HwQ5o5RzCauJSIcyGyzPlIJHMYtaA2spBmnRvTmcL0S+bfb/UovUwBAn7WAKckUH
Qv0TuRMMZG3xaV5h4tdrW3hgSw1wZFfEG9cxViz6cr7FOTOEfOAjtU3M8v2/f21i
4o7w5ZORwAlUONamQ0C9x5CNccvNZln5vrpdcL+vqSc=</ds:SignatureValue>
				<ds:KeyInfo>
					<ds:X509Data>
						<X509Certificate xmlns="http://www.w3.org/2000/09/xmldsig#">(big long block of text I cut out for brevity)</X509Certificate>
						<X509IssuerSerial xmlns="http://www.w3.org/2000/09/xmldsig#">
							<X509IssuerName>CN=Thawte Test CA Root,OU=TEST TEST TEST,O=Thawte Certification,ST=FOR TESTING PURPOSES ONLY,C=ZA</X509IssuerName>
							<X509SerialNumber>5328</X509SerialNumber>
						</X509IssuerSerial>
					</ds:X509Data>
				</ds:KeyInfo>
			</ds:Signature>

What you are - Asked By Aarthi Saravanakumar on 12-Oct-05 09:39 AM

sending is a X509 certificate.Basically your web service will be set up for Client Certificates--> meaning that the SOAP request will be accepted only if accompanied by certain Client certificates that you distribute before hand.
You basically load the Certifcate from a file like
this
X509certificate cert = X509certificate.CreateFromCertFile("C:\\test.cer");
//Now add to the proxy created
proxy1.Certificates.Add(cert);
//Make web service call
proxy1.SomeMeth();

Not a web service call - Asked By Bradley Ward on 12-Oct-05 09:57 AM

Aarthi, thanks for the quick reply. Unfortunately, I am not dealing with a full blown web service (i.e. no WSDL to work from). I am supposed to just create the SOAP message and post it to a URL. So I am assuming (and I could be wrong) that I have to (1) create the SOAP message, then (2) digitally sign it (i.e. generate and add the <ds:Signature> element and add it as a child to the <SOAP-SEC:Security> element in the <soap:Header> element. So I won't have a proxy element.
Sorry for not being clearer on this.
Any ideas?
Thanks,
Brad

Not sure what the method you are adopting for - Asked By Aarthi Saravanakumar on 12-Oct-05 10:50 AM

constructing the SOAP message
<ds:X509Data> 
<X509Certificate xmlns="http://www.w3.org/2000/09/xmldsig#">(big long block of text I cut out for brevity)</X509Certificate> 
<X509IssuerSerial xmlns="http://www.w3.org/2000/09/xmldsig#;"> 
<X509IssuerName>CN=Thawte Test CA Root,OU=TEST TEST TEST,O=Thawte Certification,ST=FOR TESTING PURPOSES ONLY,C=ZA</X509IssuerName> 
<X509SerialNumber>5328</X509SerialNumber> 
</X509IssuerSerial> 
</ds:X509Data>
But this is what needs to go into these elements.
Load the X509 certificate as in my previous post and 
Use the following methods to populate the XML elements. 
#####Warning Untested
element Name "X509Certificate"-->cert.GetCertHashString() ;
element Name "X509IssuerName"-->cert.GetName();
element Name "X509SerialNumber"-->cert.GetSerialNumber();
Hope this helps
I got it working! Well, not quite - Asked By Bradley Ward on 12-Oct-05 06:04 PM
Well, I got my X509 code running so that it successfully generates a digital signature and adds it to the Header node of the SOAP message under construction. It loads a SOAP message that is complete but has not been signed from the file t1.xml, then signs it and writes it back to t2.xml.
And I wrote another function that tests the signature. This one loads the t2.xml file that was generated in the previous paragraph, then checks the digital signature.
Everything seems to run just fine. Only trouble is the signature check fails!
As you will see in the code below, the signature information is constructed from the cert in the "creation" method, and is loaded from the embedded tag in the SOAP header in the method that tests the signature. I've dumped out all sorts of information about both the body (that is the section being signed) and the signature itself, and everthing matches. But the  CheckSignature() still returns false!
This does not seem to be that hard, but there sure are a lot of little pieces that all have to line up before anything works! Any suggestions woudl be much appreciated!
Thanks,
Brad
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Xml;
using Microsoft.Web.Services2.Security.X509;
namespace DigitalSignatureSandbox
{
	/// <summary>
	/// Summary description for frmMain.
	/// </summary>
	public class frmMain : System.Windows.Forms.Form
	{
		private const string SOAP_PREFIX = "soap";
		private const string SOAP_NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/";
		private const string SOAP_SEC_PREFIX = "SOAP-SEC";
		private const string SOAP_SEC_NAMESPACE="http://schemas.xmlsoap.org/soap/security/2000-12";
		private const string DS_PREFIX = "ds";
		//private const string DS_NAMESPACE = "http://www.w3.org/2000/09/xmldsig#";
		private const string DS_NAMESPACE = SignedXml.XmlDsigNamespaceUrl;
		private const string FOLDER = "C:/Visual Studio Projects/SOAPSandbox/SOAPSandbox/";
		private const string INPUT_FILE = FOLDER + "t1.xml";
		private const string OUTPUT_FILE = FOLDER + "t2.xml";
		private string m_publicKey = null;
--- deleted boilerplate code generated by Visual Studio ---
		private void frmMain_Load(object sender, System.EventArgs e)
		{
			SignSOAPMessage();
			VerifySignature();
			Close();
		}
		private void SignSOAPMessage()
		{
			// Load the SOAP message to be signed from a file
			// ----------------------------------------------
			XmlDocument document = new XmlDocument();
			document.Load(INPUT_FILE);
			// Load the certificate used to sign the SOAP message
			// --------------------------------------------------
			System.Security.Cryptography.X509Certificates.X509Certificate cert = FindCertByName("BradleyWard");
			m_publicKey = cert.GetPublicKeyString();
			Console.WriteLine("PublicKey=" + m_publicKey);
			// Get the SOAP messages <Header> and <Body> elements.
			// ---------------------------------------------------
			XmlElement bodyNode = GetSingleElement("Body",SOAP_NAMESPACE,document,true);
			XmlElement headerNode = GetSingleElement("Header",SOAP_NAMESPACE,document,true);
			// Create the SignedXml instance that will be used
			// to generate the digital signature of the 
			// Envelope/Body portion of the SOAP message.
			// -----------------------------------------------
			SignedXml signer = new SignedXml(bodyNode);
			// Create a reference to the <soap:Body> element.
			// ----------------------------------------------
			Transform transform = new XmlDsigC14NTransform(false);
			Reference reference = new Reference("#body");
			reference.AddTransform(transform);
			signer.AddReference(reference);
			SignedInfo signedInfo = signer.SignedInfo;
			// Add KeyInfo
			// -----------
			KeyInfo keyInfo = new KeyInfo();
			DSACryptoServiceProvider key = new DSACryptoServiceProvider();
			signer.SigningKey = key;
			KeyInfoX509Data clause = new KeyInfoX509Data(cert);
			clause.AddIssuerSerial(cert.GetIssuerName(),cert.GetSerialNumberString());
			keyInfo.AddClause(clause);
			signer.KeyInfo = keyInfo;
			// Compute the actual digital signature
			// ------------------------------------
			signer.ComputeSignature();
			dump("signer",signer);
			XmlElement digitalSignature = signer.GetXml();
			// Get the <SOAP-SEC:Security> node from the SOAP
			// document being signed.
			// ----------------------------------------------
			XmlElement securityNode = GetSingleElement("Security",SOAP_SEC_NAMESPACE,document,false);
			if (securityNode == null)
			{
				// <SOAP-SEC:Security> node does not exist. Create it.
				// ---------------------------------------------------
				securityNode = document.CreateElement(SOAP_SEC_PREFIX,"Security",SOAP_SEC_NAMESPACE);
				headerNode.AppendChild(securityNode);
			} 
			else 
			{
				// <SOAP-SEC:Security> node DOES exist.
				// Make sure it is empty.
				// ------------------------------------
				securityNode.RemoveAll();
			}
			// Add the digital signature to the
			// <SOAP-SEC:Security> node.
			// --------------------------------
			securityNode.AppendChild(digitalSignature);
			headerNode.AppendChild(securityNode);
			// Save the signed SOAP message to a file
			// --------------------------------------
			XmlTextWriter w = new XmlTextWriter(OUTPUT_FILE,new UTF8Encoding(false));
			document.WriteTo(w);
			w.Close();
		}
		private XmlElement GetSingleElement(string localName,string namespaceURI,XmlDocument document,bool throwException)
		{
			XmlNodeList list = document.DocumentElement.GetElementsByTagName(localName,namespaceURI);
			if (list == null || list.Count == 0)
			{
				if (throwException)
				{
					string msg = "<" + localName + "> tag in SOAP message not found!\nNamespace=" + namespaceURI;
					throw new ApplicationException(msg);
				}
				return null;
			} 
			else if (list.Count > 1)
			{
				if (throwException)
				{
					string msg = list.Count + " <" + localName + "> tags found in the SOAP message XML!\nNamespace=" + namespaceURI;
					throw new ApplicationException(msg);
				}
				return null;
			}
			XmlElement singleElement = (XmlElement)list[0];
			return singleElement;
		}
		/// <summary>
		/// Locate a security certificate from the certificate
		/// store using the certificates simple display name.
		/// </summary>
		/// <remarks>
		/// Throws ApplicationException if the named certificate has
		/// not been installed on the system.
		/// </remarks>
		/// <param name="simpleName">The simple display name of the cert to be located.</param>
		/// <returns>The certificate.</returns>
		private System.Security.Cryptography.X509Certificates.X509Certificate FindCertByName(string simpleName)
		{
			X509CertificateStore  store = X509CertificateStore.CurrentUserStore(
				X509CertificateStore.RootStore.ToString());
			store.OpenRead();
			foreach(Microsoft.Web.Services2.Security.X509.X509Certificate cert in store.Certificates)
			{
				if (simpleName.Equals(cert.SimpleDisplayName))
				{
					return cert;
				}				
			}
			string msg = "The '" + simpleName + "' security certificate is not installed on this system!";
			throw new ApplicationException(msg);
		}
		private void VerifySignature()
		{
			XmlDocument document = new XmlDocument();
			document.Load(OUTPUT_FILE);
			// Get the SOAP messages <Header> and <Body> elements.
			// ---------------------------------------------------
			XmlElement bodyNode = GetSingleElement("Body",SOAP_NAMESPACE,document,true);
			XmlElement signatureNode = GetSingleElement("Signature",SignedXml.XmlDsigNamespaceUrl,document,true);
			// Create the SignedXml instance that will be used
			// to verify the digital signature on the document
			// -----------------------------------------------
			SignedXml verifier = new SignedXml(document);
			// Create a reference to the <soap:Body> element.
			// ----------------------------------------------
// I've tried this with and without the next 4 lines,
//  and neither approach works...
//			Transform transform = new XmlDsigC14NTransform(false);
//			Reference reference = new Reference("#body");
//			reference.AddTransform(transform);
//			verifier.AddReference(reference);
			// Load the SignedXml instance from the 
			// XML data that is in the 
			// <SOAP-SEC:Security><ds:Signature> node.
			// ---------------------------------------
			verifier.LoadXml(signatureNode);
			dump("verifier",verifier);
			// Is the file secure?
			// -------------------
			bool isValid = verifier.CheckSignature();
			string msg = "Output file isValid = " + isValid;
			Console.WriteLine(msg);
			MessageBox.Show(msg);
		}
		private void dump(string name,SignedXml signedXml)
		{
			XmlDocument document = signedXml.GetXml().OwnerDocument;
			string signatureXML = signedXml.GetXml().OuterXml;
			XmlElement bodyNode = signedXml.GetIdElement(document,"body");
			string bodyXML = bodyNode.OuterXml;
			string keyInfo = signedXml.KeyInfo.GetXml().OuterXml;
			Console.WriteLine("----- " + name + " -----");
			Console.WriteLine("   SignatureXML=" + signatureXML);
			Console.WriteLine("   BodyXML=" + bodyXML);
			Console.WriteLine("   Signature=" + signedXml.GetXml().OuterXml);
			Console.WriteLine("   SignatureValue=" + ToString(signedXml.Signature.SignatureValue));
			Console.WriteLine("   Key Info=" + keyInfo);
			Console.WriteLine("   SignatureXML.HashCode = " + signatureXML.GetHashCode());
			Console.WriteLine("   BodyXML.HashCode = " + bodyXML.GetHashCode());
			Console.WriteLine("------------------------");
		}
		private string ToString(byte[] bytes)
		{
			StringBuilder s = new StringBuilder();
			for (int i=0;i<bytes.Length;i++)
			{
				s.Append(String.Format("{0:d2}",bytes[i]));
				s.Append(" ");
			}
			return s.ToString().TrimEnd();
		}
	}
}
Output when this program is run:
PublicKey=30818902818100E8B5B6E2914464ED1A7D8631AF8D10F5C7DB082D2DA8825A219D126AF71A827DBD71B78CA5DB57B2187759384D3FEA97876758421D1C71C2CD346E90AB1C43D9DF3FE503EC6A73D1EB6A814DF9B4EB02EA6E25829044DD0D41E76DE039541848524E3BF425967DE5BA8FAF94FE514B71EF3C937FC156389A00CEDC3A7E6EA8050203010001
----- signer -----
   SignatureXML=<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" /><Reference URI="#body"><Transforms><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>9JnBIV4RUloZ1UYe6mXb7Vidouk=</DigestValue></Reference></SignedInfo><SignatureValue>gVL3o1LzaV9dTijxgjSxvux3VWE6LZhIISiha//9Xd172T3KDHzqKw==</SignatureValue><KeyInfo><X509Data xmlns="http://www.w3.org/2000/09/xmldsig#"><X509IssuerSerial><X509IssuerName>CN=Root Agency</X509IssuerName><X509SerialNumber>D02B1C98E1F3B54B9D43C56606DC20F1</X509SerialNumber></X509IssuerSerial><X509Certificate>MIIBuzCCAWWgAwIBAgIQ8SDcBmbFQ51LtfPhmBwr0DANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wNTEwMTEyMzU2NTBaFw0zOTEyMzEyMzU5NTlaMBYxFDASBgNVBAMTC0JyYWRsZXlXYXJkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDotbbikURk7Rp9hjGvjRD1x9sILS2oglohnRJq9xqCfb1xt4yl21eyGHdZOE0/6peHZ1hCHRxxws00bpCrHEPZ3z/lA+xqc9HraoFN+bTrAupuJYKQRN0NQedt4DlUGEhSTjv0JZZ95bqPr5T+UUtx7zyTf8FWOJoAztw6fm6oBQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQBZwOR/j1C29ctTJQVmxY7VeY9r1zU6Zr/2BS9WgC4+BLmWnrOp4dXUmKP/Ebkz7mHArTjbS6o49N+xflBW91aD</X509Certificate></X509Data></KeyInfo></Signature>
   BodyXML=<soap:Body Id="body" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><star:ProcessCreditApplication xmlns:star="http://www.starstandards.org/STAR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.starstandards.org/STAR Star Rev1.1BODsProcessCreditApplication.xsd"><star:ApplicationArea><star:Sender><star:LogicalId>www.coindata.com</star:LogicalId><star:Component>DocuPen</star:Component><star:Task>CreditApplication</star:Task><star:ReferenceId>21576</star:ReferenceId><star:AuthorizationId>DocuPen</star:AuthorizationId><star:CreatorNameCode>DocuPen</star:CreatorNameCode><star:SenderNameCode>JJ</star:SenderNameCode><star:StoreNumber>1</star:StoreNumber></star:Sender><star:CreationDateTime>2005-10-10T21:29:37.04</star:CreationDateTime><star:Destination><star:DestinationNameCode>RO</star:DestinationNameCode></star:Destination></star:ApplicationArea><star:DataArea><oagis:Process xmlns:oagis="http://www.openapplications.org/oagis" /><star:CreditApplication><star:Header><star:DocumentDateTime>2005-10-10T21:29:37.04</star:DocumentDateTime><star:DocumentId>JJ-1-101</star:DocumentId><star:FinanceCompany><star:PartyId>F000JJ</star:PartyId></star:FinanceCompany><star:Dealer><star:PartyId>VJ2FO</star:PartyId></star:Dealer><star:ApplicationStatus>N</star:ApplicationStatus></star:Header><star:Detail /></star:CreditApplication></star:DataArea></star:ProcessCreditApplication></soap:Body>
   Signature=<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" /><Reference URI="#body"><Transforms><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>9JnBIV4RUloZ1UYe6mXb7Vidouk=</DigestValue></Reference></SignedInfo><SignatureValue>gVL3o1LzaV9dTijxgjSxvux3VWE6LZhIISiha//9Xd172T3KDHzqKw==</SignatureValue><KeyInfo><X509Data xmlns="http://www.w3.org/2000/09/xmldsig#"><X509IssuerSerial><X509IssuerName>CN=Root Agency</X509IssuerName><X509SerialNumber>D02B1C98E1F3B54B9D43C56606DC20F1</X509SerialNumber></X509IssuerSerial><X509Certificate>MIIBuzCCAWWgAwIBAgIQ8SDcBmbFQ51LtfPhmBwr0DANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wNTEwMTEyMzU2NTBaFw0zOTEyMzEyMzU5NTlaMBYxFDASBgNVBAMTC0JyYWRsZXlXYXJkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDotbbikURk7Rp9hjGvjRD1x9sILS2oglohnRJq9xqCfb1xt4yl21eyGHdZOE0/6peHZ1hCHRxxws00bpCrHEPZ3z/lA+xqc9HraoFN+bTrAupuJYKQRN0NQedt4DlUGEhSTjv0JZZ95bqPr5T+UUtx7zyTf8FWOJoAztw6fm6oBQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQBZwOR/j1C29ctTJQVmxY7VeY9r1zU6Zr/2BS9WgC4+BLmWnrOp4dXUmKP/Ebkz7mHArTjbS6o49N+xflBW91aD</X509Certificate></X509Data></KeyInfo></Signature>
   SignatureValue=129 82 247 163 82 243 105 95 93 78 40 241 130 52 177 190 236 119 85 97 58 45 152 72 33 40 161 107 255 253 93 221 123 217 61 202 12 124 234 43
   Key Info=<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"><X509Data xmlns="http://www.w3.org/2000/09/xmldsig#"><X509IssuerSerial><X509IssuerName>CN=Root Agency</X509IssuerName><X509SerialNumber>D02B1C98E1F3B54B9D43C56606DC20F1</X509SerialNumber></X509IssuerSerial><X509Certificate>MIIBuzCCAWWgAwIBAgIQ8SDcBmbFQ51LtfPhmBwr0DANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wNTEwMTEyMzU2NTBaFw0zOTEyMzEyMzU5NTlaMBYxFDASBgNVBAMTC0JyYWRsZXlXYXJkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDotbbikURk7Rp9hjGvjRD1x9sILS2oglohnRJq9xqCfb1xt4yl21eyGHdZOE0/6peHZ1hCHRxxws00bpCrHEPZ3z/lA+xqc9HraoFN+bTrAupuJYKQRN0NQedt4DlUGEhSTjv0JZZ95bqPr5T+UUtx7zyTf8FWOJoAztw6fm6oBQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQBZwOR/j1C29ctTJQVmxY7VeY9r1zU6Zr/2BS9WgC4+BLmWnrOp4dXUmKP/Ebkz7mHArTjbS6o49N+xflBW91aD</X509Certificate></X509Data></KeyInfo>
   SignatureXML.HashCode = -1493349219
   BodyXML.HashCode = -254931685
------------------------
----- verifier -----
   SignatureXML=<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" /><Reference URI="#body"><Transforms><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>9JnBIV4RUloZ1UYe6mXb7Vidouk=</DigestValue></Reference></SignedInfo><SignatureValue>gVL3o1LzaV9dTijxgjSxvux3VWE6LZhIISiha//9Xd172T3KDHzqKw==</SignatureValue><KeyInfo><X509Data xmlns="http://www.w3.org/2000/09/xmldsig#"><X509IssuerSerial><X509IssuerName>CN=Root Agency</X509IssuerName><X509SerialNumber>D02B1C98E1F3B54B9D43C56606DC20F1</X509SerialNumber></X509IssuerSerial><X509Certificate>MIIBuzCCAWWgAwIBAgIQ8SDcBmbFQ51LtfPhmBwr0DANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wNTEwMTEyMzU2NTBaFw0zOTEyMzEyMzU5NTlaMBYxFDASBgNVBAMTC0JyYWRsZXlXYXJkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDotbbikURk7Rp9hjGvjRD1x9sILS2oglohnRJq9xqCfb1xt4yl21eyGHdZOE0/6peHZ1hCHRxxws00bpCrHEPZ3z/lA+xqc9HraoFN+bTrAupuJYKQRN0NQedt4DlUGEhSTjv0JZZ95bqPr5T+UUtx7zyTf8FWOJoAztw6fm6oBQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQBZwOR/j1C29ctTJQVmxY7VeY9r1zU6Zr/2BS9WgC4+BLmWnrOp4dXUmKP/Ebkz7mHArTjbS6o49N+xflBW91aD</X509Certificate></X509Data></KeyInfo></Signature>
   BodyXML=<soap:Body Id="body" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><star:ProcessCreditApplication xmlns:star="http://www.starstandards.org/STAR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.starstandards.org/STAR Star Rev1.1BODsProcessCreditApplication.xsd"><star:ApplicationArea><star:Sender><star:LogicalId>www.coindata.com</star:LogicalId><star:Component>DocuPen</star:Component><star:Task>CreditApplication</star:Task><star:ReferenceId>21576</star:ReferenceId><star:AuthorizationId>DocuPen</star:AuthorizationId><star:CreatorNameCode>DocuPen</star:CreatorNameCode><star:SenderNameCode>JJ</star:SenderNameCode><star:StoreNumber>1</star:StoreNumber></star:Sender><star:CreationDateTime>2005-10-10T21:29:37.04</star:CreationDateTime><star:Destination><star:DestinationNameCode>RO</star:DestinationNameCode></star:Destination></star:ApplicationArea><star:DataArea><oagis:Process xmlns:oagis="http://www.openapplications.org/oagis" /><star:CreditApplication><star:Header><star:DocumentDateTime>2005-10-10T21:29:37.04</star:DocumentDateTime><star:DocumentId>JJ-1-101</star:DocumentId><star:FinanceCompany><star:PartyId>F000JJ</star:PartyId></star:FinanceCompany><star:Dealer><star:PartyId>VJ2FO</star:PartyId></star:Dealer><star:ApplicationStatus>N</star:ApplicationStatus></star:Header><star:Detail /></star:CreditApplication></star:DataArea></star:ProcessCreditApplication></soap:Body>
   Signature=<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" /><Reference URI="#body"><Transforms><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>9JnBIV4RUloZ1UYe6mXb7Vidouk=</DigestValue></Reference></SignedInfo><SignatureValue>gVL3o1LzaV9dTijxgjSxvux3VWE6LZhIISiha//9Xd172T3KDHzqKw==</SignatureValue><KeyInfo><X509Data xmlns="http://www.w3.org/2000/09/xmldsig#"><X509IssuerSerial><X509IssuerName>CN=Root Agency</X509IssuerName><X509SerialNumber>D02B1C98E1F3B54B9D43C56606DC20F1</X509SerialNumber></X509IssuerSerial><X509Certificate>MIIBuzCCAWWgAwIBAgIQ8SDcBmbFQ51LtfPhmBwr0DANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wNTEwMTEyMzU2NTBaFw0zOTEyMzEyMzU5NTlaMBYxFDASBgNVBAMTC0JyYWRsZXlXYXJkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDotbbikURk7Rp9hjGvjRD1x9sILS2oglohnRJq9xqCfb1xt4yl21eyGHdZOE0/6peHZ1hCHRxxws00bpCrHEPZ3z/lA+xqc9HraoFN+bTrAupuJYKQRN0NQedt4DlUGEhSTjv0JZZ95bqPr5T+UUtx7zyTf8FWOJoAztw6fm6oBQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQBZwOR/j1C29ctTJQVmxY7VeY9r1zU6Zr/2BS9WgC4+BLmWnrOp4dXUmKP/Ebkz7mHArTjbS6o49N+xflBW91aD</X509Certificate></X509Data></KeyInfo></Signature>
   SignatureValue=129 82 247 163 82 243 105 95 93 78 40 241 130 52 177 190 236 119 85 97 58 45 152 72 33 40 161 107 255 253 93 221 123 217 61 202 12 124 234 43
   Key Info=<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"><X509Data xmlns="http://www.w3.org/2000/09/xmldsig#"><X509IssuerSerial><X509IssuerName>CN=Root Agency</X509IssuerName><X509SerialNumber>D02B1C98E1F3B54B9D43C56606DC20F1</X509SerialNumber></X509IssuerSerial><X509Certificate>MIIBuzCCAWWgAwIBAgIQ8SDcBmbFQ51LtfPhmBwr0DANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wNTEwMTEyMzU2NTBaFw0zOTEyMzEyMzU5NTlaMBYxFDASBgNVBAMTC0JyYWRsZXlXYXJkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDotbbikURk7Rp9hjGvjRD1x9sILS2oglohnRJq9xqCfb1xt4yl21eyGHdZOE0/6peHZ1hCHRxxws00bpCrHEPZ3z/lA+xqc9HraoFN+bTrAupuJYKQRN0NQedt4DlUGEhSTjv0JZZ95bqPr5T+UUtx7zyTf8FWOJoAztw6fm6oBQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQBZwOR/j1C29ctTJQVmxY7VeY9r1zU6Zr/2BS9WgC4+BLmWnrOp4dXUmKP/Ebkz7mHArTjbS6o49N+xflBW91aD</X509Certificate></X509Data></KeyInfo>
   SignatureXML.HashCode = -1493349219
   BodyXML.HashCode = -254931685
------------------------
Output file isValid = False
How can you delete multiple security certificates - Asked By Bradley Ward on 13-Oct-05 10:30 AM
Raymond replied to Bradley Ward on 09-Mar-10 09:53 PM
Hi Bradley,

Sorry to ask for asking question for a long time ago thread. However, am facing the same issue as you faced previously which the signature check is failed. Do you mind to share your solution, if any?

Thank you.
Jackson Hoe replied to Bradley Ward on 05-May-10 09:07 AM
Any chance to get in VB.NEt

Thanks
satya replied to Bradley Ward on 12-May-10 03:39 PM
Hi Brad,

I am also working with similar type of problem, i.e adding the signature in the soap envelope header and signing the content of the body.

Did you got solution for your problem? If you got it, can you please post your working solution. ( I think it would include just few modifications for the already posted solution).

 urgent please respond ASAP.
Any help woud be apprciated.

Thanks
Satya

Bradley Ward replied to satya on 12-May-10 06:30 PM
I did get it working, but that was 5 years ago and I no longer work for that company so I cannot get to their source code. Also, it is very hard to remember something like this because this is something that once you get working, you never go back and work with anymore.

My apologies,

Brad
satya replied to Bradley Ward on 12-May-10 07:36 PM
It seems i am working on same stuff that you worked 5 years back. I  am also working for automobile company. Because Header & body of the SOAP envelope matches mine ( exactly matches). So i am very excited about it.

http://www.west-wind.com/weblog/posts/257599.aspx

The above blog looks similar:

Let me know if I have any chances of luck.

Thanks for the quick luck.
angel adinolffi replied to Bradley Ward on 18-Nov-13 07:22 PM
Hi, look at this blog, explains in a very clear example

http://www.systemdeveloper.info/2013/11/digital-signature-in-c.html