title: Encrypt xml file
body: <pre><code>makecert -r -pe -n "CN=CERT_SIGN_TEST_CERT" -b 01/01/2010 -e 01/01/2012 -sky exchange -ss my
  </code></pre>
  
  <p>using this command i generate certificate and exported .pfx file from that and this pfx file is used to encrypt the xml file</p>
  
  <blockquote>
    <p>in .net using EncryptedXml , X509Certificate2, RSACryptoServiceProvider and 
    XmlDocument classes</p>
  </blockquote>
  
  <p>i encrypt following xml </p>
  
  <pre><code>&lt;Test&gt;&lt;Name&gt;Foo&lt;/Name&gt;&lt;CardNo&gt;123&lt;/CardNo&gt;&lt;/Test&gt;
  </code></pre>
  
  <p>as follows:</p>
  
  <pre><code>&lt;EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"&gt;&lt;EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" /&gt;&lt;KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;&lt;EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"&gt;&lt;EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /&gt;&lt;KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;&lt;X509Data&gt;&lt;X509Certificate&gt;MIICFzCCAYCgAwIBAgIQK5IFtxwNaJhGzXuDf92TgzANBgkqhkiG9w0BAQQFADAfMR0wGwYDVQQDHhQARgBpAG4AYQBsAF8AQwBlAHIAdDAeFw0wOTEyMzExODMwMDBaFw0xMjEyMzExODMwMDBaMB8xHTAbBgNVBAMeFABGAGkAbgBhAGwAXwBDAGUAcgB0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1Wx11luboMbT1swXV/56j2RYRhR81n9hF3b6tfof1zHRorg7DIP3hvnVtqDF+WxAjn1um97DHtxWf3solthbIHC9cGtqxUhZhgdd0aVAuiKTBbTgnOWdEqTErenrHOzlZnD9iDzOm3OYVLKN+3hKJmjlhTp0sFsu4AIbXlxZVHQIDAQABo1QwUjBQBgNVHQEESTBHgBBDXPlnSZ5zUyVbxJzJO12goSEwHzEdMBsGA1UEAx4UAEYAaQBuAGEAbABfAEMAZQByAHSCECuSBbccDWiYRs17g3/dk4MwDQYJKoZIhvcNAQEEBQADgYEAiubZJZdF3Y9ItOl7LTyixcbuebs50GLFsTeMslS3usq6psXcUEFJntXJ5vXOSe/vp6E6A5AwW4MtPfnB1kzach4T4+WlWeaDHoyj6y5j+n7P6B/X6ZhkQ8MCiGhZ/fTOt7CDisnFVG9gvoH2LUEs1QkiByDq6jii3TUAMN9YQdA=&lt;/X509Certificate&gt;&lt;/X509Data&gt;&lt;/KeyInfo&gt;&lt;CipherData&gt;&lt;CipherValue&gt;Vyml+mtbeL5bE6EWKNqHfnE1xEkbJglcxbjH3Y7pj9BtXVImAI/SbBdLHatyjIAei7qUfhcn+qYC7WAh48XR78BgqCdJX7O5lfZjVSVeVaQUwl1Bdirdz7RYuveIjDtEIM80W4tB6rq2nOgYNkisxhhwIl7EiCQtT42bSGCKFic=&lt;/CipherValue&gt;&lt;/CipherData&gt;&lt;/EncryptedKey&gt;&lt;/KeyInfo&gt;&lt;CipherData&gt;&lt;CipherValue&gt;ezVeQlBGZRbHqitB2mmHuMvifGB9IhG1g0CWmL8iz37JIIw7x5cGbb5Ap8iy24ACu8TJpwgAGIUWnUTDSZ//kWLzCa3G5HL+jT/RHn+zypk=&lt;/CipherValue&gt;&lt;/CipherData&gt;&lt;/EncryptedData&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code> EncryptedXml encXml = new EncryptedXml(xmlEncDoc);  
  encXml.DecryptDocument();
  </code></pre>
  
  <p>How can i decrypt in java, should i pass pfx file to java end? as there is  tag in encrypted xml file.</p>
  
  <p>your suggestion is appriciated.</p>