Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi
My client has signed the xml in Java using private key & IAIK tool. I want to decrypt/verify the data in .NET 2.0. I have public certificate of my client. I have tried various methods but verification fails. Kindly suggest any code to verify/decrypt the data. The signed XML is as follows
XML
<TrnResponse>
 <Transaction>
  <Type>TrnResponse</MessageType>
  <ReferenceNo>123456</ReferenceNo>
  <ClientName>ABCDI</ClientName>
  <TReferenceNo>111111</CTReferenceNo>
  <Mode>05</Mode>
  <Status>SUCCESSFUL</Status>
  <TRXDateTime>06-03-2012 13:16:21</TRXDateTime>
  <TRXID>001111222</TRXID>
  </Transaction>
 <Signature>  <SignatureValue>MIAGCSqGSIb3DQEHAqCAMIIHlwIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcB</SignatureValue>
  </Signature>
</TrnResponse>

i am trying following code to verify
C#
XmlDocument Doc = new XmlDocument();
        Doc.PreserveWhitespace = false;
        Doc.Load(@"d:\data.xml");
        SignedXml signedXml = new SignedXml(Doc);
        XmlNodeList nodeList = Doc.GetElementsByTagName("Signature");

        X509Certificate2 cert = GetRecipientCert(); // method returns public certificate
        RSACryptoServiceProvider csp = (RSACryptoServiceProvider)cert.PublicKey.Key;

        string publickey = cert.PublicKey.Key.ToXmlString(false);

        XmlNodeList xn1 = Doc.GetElementsByTagName("Transaction");
        string license_code = xn1.Item(0).OuterXml.ToString();
        ASCIIEncoding ByteConverter = new ASCIIEncoding();
        byte[] verify_this = ByteConverter.GetBytes(license_code);
        string base64_encoded_signature = Doc.GetElementsByTagName("SignatureValue").Item(0).InnerText;
        byte[] signature = Convert.FromBase64String(base64_encoded_signature);
        bool ok = csp.VerifyData(verify_this, new SHA1CryptoServiceProvider(), signature);
Posted
Updated 4-Apr-12 2:44am
v2
Comments
Bernhard Hiller 4-Apr-12 9:36am    
Do you know for sure which pieces of the xml message were used for generating the signature? E.g. with or without spaces, tags, line breaks,...
ajay_sp002 5-Apr-12 6:04am    
Hi,

The xml is provided by my client. I think they are using complete transaction tag for generating signature & i.e. without spaces.
walterhevedeich 16-Apr-12 1:59am    
Do you know which cryptographic algorithm was used by your client to encrypt the data?
ajay_sp002 17-Apr-12 2:47am    
Hi,

They are using SHA1 algorithm for encrypt data.
surekha116 11-Jun-13 9:29am    
Hi ajay,

I have the same issue now,

Could you please help me how you solved this issue .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900