Smack
Smack

Reputation: 946

Encrypt xml file

makecert -r -pe -n "CN=CERT_SIGN_TEST_CERT" -b 01/01/2010 -e 01/01/2012 -sky exchange -ss my

using this command i generate certificate and exported .pfx file from that and this pfx file is used to encrypt the xml file

in .net using EncryptedXml , X509Certificate2, RSACryptoServiceProvider and XmlDocument classes

i encrypt following xml

<Test><Name>Foo</Name><CardNo>123</CardNo></Test>

as follows:

<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"><EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" /><KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"><EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"><EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /><KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"><X509Data><X509Certificate>MIICFzCCAYCgAwIBAgIQK5IFtxwNaJhGzXuDf92TgzANBgkqhkiG9w0BAQQFADAfMR0wGwYDVQQDHhQARgBpAG4AYQBsAF8AQwBlAHIAdDAeFw0wOTEyMzExODMwMDBaFw0xMjEyMzExODMwMDBaMB8xHTAbBgNVBAMeFABGAGkAbgBhAGwAXwBDAGUAcgB0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1Wx11luboMbT1swXV/56j2RYRhR81n9hF3b6tfof1zHRorg7DIP3hvnVtqDF+WxAjn1um97DHtxWf3solthbIHC9cGtqxUhZhgdd0aVAuiKTBbTgnOWdEqTErenrHOzlZnD9iDzOm3OYVLKN+3hKJmjlhTp0sFsu4AIbXlxZVHQIDAQABo1QwUjBQBgNVHQEESTBHgBBDXPlnSZ5zUyVbxJzJO12goSEwHzEdMBsGA1UEAx4UAEYAaQBuAGEAbABfAEMAZQByAHSCECuSBbccDWiYRs17g3/dk4MwDQYJKoZIhvcNAQEEBQADgYEAiubZJZdF3Y9ItOl7LTyixcbuebs50GLFsTeMslS3usq6psXcUEFJntXJ5vXOSe/vp6E6A5AwW4MtPfnB1kzach4T4+WlWeaDHoyj6y5j+n7P6B/X6ZhkQ8MCiGhZ/fTOt7CDisnFVG9gvoH2LUEs1QkiByDq6jii3TUAMN9YQdA=</X509Certificate></X509Data></KeyInfo><CipherData><CipherValue>Vyml+mtbeL5bE6EWKNqHfnE1xEkbJglcxbjH3Y7pj9BtXVImAI/SbBdLHatyjIAei7qUfhcn+qYC7WAh48XR78BgqCdJX7O5lfZjVSVeVaQUwl1Bdirdz7RYuveIjDtEIM80W4tB6rq2nOgYNkisxhhwIl7EiCQtT42bSGCKFic=</CipherValue></CipherData></EncryptedKey></KeyInfo><CipherData><CipherValue>ezVeQlBGZRbHqitB2mmHuMvifGB9IhG1g0CWmL8iz37JIIw7x5cGbb5Ap8iy24ACu8TJpwgAGIUWnUTDSZ//kWLzCa3G5HL+jT/RHn+zypk=</CipherValue></CipherData></EncryptedData>

as far as encryption is done using w3c standard. How can i decrypt this xml file on java. I have used .pfx file to encrypt the file. In .net i can decrypt file using following:

 EncryptedXml encXml = new EncryptedXml(xmlEncDoc);  
encXml.DecryptDocument();

How can i decrypt in java, should i pass pfx file to java end? as there is tag in encrypted xml file.

your suggestion is appriciated.

Upvotes: 3

Views: 1148

Answers (1)

James Turner
James Turner

Reputation: 46

Do you have control over the sender and recipient of the XML message? It would be best to follow the W3 standard for XML Signatures. Java 6 includes full support for digital signatures and there is a good tutorial available which explains how to do it.

Upvotes: 3

Related Questions