Friday, May 15, 2015

Encryption/Decryption of XML file

You might have encrypt and decrypt a sting value using various cryptographic algorithms and you might have build C programs for that as well. In this tutorial I am going to show you how to Encrypt and Decrypt a XML file using OpenSSL and XMLSec.

Things you need:

XML file - The file you need to encrypt/decrypt
OpenSSL - To generate public/private keys
XMLSec - To encrypt/decrypt XML file
Template file - Needed for encryption

Step 1:

Locate your XML file.

I have used books.xml file:
<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies,
      an evil sorceress, and her own childhood to become queen
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology
      society in England, the young survivors lay the
      foundation for a new society.</description>
   </book>
   <book id="bk104">
      <author>Corets, Eva</author>
      <title>Oberon's Legacy</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-03-10</publish_date>
      <description>In post-apocalypse England, the mysterious
      agent known only as Oberon helps to create a new life
      for the inhabitants of London. Sequel to Maeve
      Ascendant.</description>
   </book>
   <book id="bk105">
      <author>Corets, Eva</author>
      <title>The Sundered Grail</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-09-10</publish_date>
      <description>The two daughters of Maeve, half-sisters,
      battle one another for control of England. Sequel to
      Oberon's Legacy.</description>
   </book>
   <book id="bk106">
      <author>Randall, Cynthia</author>
      <title>Lover Birds</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-09-02</publish_date>
      <description>When Carla meets Paul at an ornithology
      conference, tempers fly as feathers get ruffled.</description>
   </book>
   <book id="bk107">
      <author>Thurman, Paula</author>
      <title>Splish Splash</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>A deep sea diver finds true love twenty
      thousand leagues beneath the sea.</description>
   </book>
   <book id="bk108">
      <author>Knorr, Stefan</author>
      <title>Creepy Crawlies</title>
      <genre>Horror</genre>
      <price>4.95</price>
      <publish_date>2000-12-06</publish_date>
      <description>An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.</description>
   </book>
   <book id="bk109">
      <author>Kress, Peter</author>
      <title>Paradox Lost</title>
      <genre>Science Fiction</genre>
      <price>6.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems
      of being quantum.</description>
   </book>
   <book id="bk110">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in
      detail in this deep programmer's reference.</description>
   </book>
   <book id="bk111">
      <author>O'Brien, Tim</author>
      <title>MSXML3: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in
      detail, with attention to XML DOM interfaces, XSLT processing,
      SAX and more.</description>
   </book>
   <book id="bk112">
      <author>Galos, Mike</author>
      <title>Visual Studio 7: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>49.95</price>
      <publish_date>2001-04-16</publish_date>
      <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are
      integrated into a comprehensive development
      environment.</description>
   </book>
</catalog>
Step 2:

Generate Public and Private Key pairs.

genrsa -out books.pem 1024
openssl rsa -in books.pem -des3 -out books-pri.pem
openssl rsa -in books.pem -pubout -out books-pub.pem


books.pem:
-----BEG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ti
TIdz8PJbg+ojf8ZJQERMRUysLDwM0NiHhZ3NSvQINVq5zEp0RtqTWWDKVl37dweo
eNwgBsDHJ/6gPcnnN+YowfAPJ1A/C0yg4KcMWe6UPfiDvHoXkb2fuPQpatBsnk3X
6+QnCTZxyNL9U3ZmPV/PaEMGK2GGIHu0NsEiPvz/pp1DuKKnZT5MMM5bS3sVPyMT
7cOMXhuFM61HLGzRqJ7tZv6vZuAgfmLLQdPGDLKmu6fkOixXt9G1YZ9SRx8LoPLv
lE0neUxXroGVfZ8fHZZjzOQ2VIh5Ozx+xV4E3tFtVsQE+awYJyn02KPS2iAgLZH0
dijIfXvJ73ZfBPtFODcFngfWrbMU8M2/eG26i9mDBgbo4JKseCB1U8Z/T5CRAY9X
1Jb55wHngS2PWGrbmOmFoPVB4wrn6098cnDrIi5G4SEufWzuMAgaTrg1Ztar8fBI
J0H/fYFp+rYfmJCAoy6gmSFWgV/lgWdtOxWc30RNBYWGnRJkphAlgAviDKs/TAS+
TRv1z8n5ZfkXRKCaf43JPCgLT4Q0JXyWiHQdL5eudFSKKr4hyvJ8wVjNqJS5kd7E
cJ2VV3vPh2CLw89YZFUDfMTIoGpqCO7dgkK6MZZY6LXC6sdIND1CAoJnLuk3Ou0t
I/Awxa9GXgRNtZ6kDBx7ndPA9ZRYjkdR/fQRgwxQ5HLDvvZRv/QOug==
-----END RSA PRIVATE KEY-----

books-pub.pem:
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCibiuAD7qoOdUMB08j8r5AEtkQ
s1RAlOSmF9TDe5eGuYqWIcvC8NBJsYWKUDTKj87Nx5VBhyvZZM0dCKfhYBQGFhut
q9ojzyHri3Ctsh4ZO7PR4MZkJqkJDUfkAJt3/5Us0gOx0gFhurFv4Piaj1aCp0Y+
Eh69qBvdK3opz/lCWwIDAQAB
-----END PUBLIC KEY-----
Step 3:

Encrypt XML file using public key.

xmlsec encrypt --pubkey-pem books-pub.pem --session-key des-192 --xml-data books.xml --output books-enc.xml template.xml


books-enc.pem:
<?xml version="1.0"?>
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element">
 <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-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#">
    <KeyName/>
   </KeyInfo>
   <CipherData>
    <CipherValue>B7+hl3/NDhsj0CmBgAvCxmXDHSlJqATYmcq3frf6hZYAaTgTwQmP4HfK0/0OlUKQ
x9PZXAXUNOBXU1cZ9MilnHpbZ8gTysivZavIOz3JOnL/YMfKkjl/Loghqz+lcYI6
kkCu5p61k5m9aQLlCAD1mOAf9NbZ5/X0spcP8RjYS3Y=</CipherValue>
   </CipherData>
  </EncryptedKey>
 </KeyInfo>
 <CipherData>
  <CipherValue>QZVDCc3zuNBu0egSRMIOKvkQy5U7sI1PWTlEJwp+/8mt5TIpRgIrtPF2/x+sSr/y
DJB4FaG+WjKCEX3LhvabPOgDBpzS9FQmiIFw5UsxNPw+vK5j+jgPvmt6QD+wyrNP
J3iAaX7WNcAXsC2pVwXBLLljgQ+qO+dcFwb63GwjpoaUGUK3ktXkWIBhUpxewJJ1
4pwnMVb1FZMz04bjrq3eAtEX4nafAFkTim0gJeY4/5B0cfe+LEMkezD4XT8hl91t
8SguUGs5eJDHOOx3aQx/AL806ae+t2TVqRlQUNhJavOOUHFg9l4a03DFmv0ic/wR
rDlpzZlA/Qsx5Iypqm6Ugm4BPofyGZ3rGVuvRhePNIjYpk5rg3bA7h1w5d5DXU5e
qJjtIB2Bs1Uw8VXg00/B2vRG3GGOutYTSgbDeKL2ICc3G++i1Bi5l8TuEV9MfXY7
YAxOlg76xc0Scq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ASc6YNjoFQ7RloP6UhemN7yiPSc2USznRCEm94+7
Lsf7KXeGhV+xHc46NQHP2GXny1To9Bzv77CBK8kYpPOWQ0KA5UZlU7js5/W+lQ1u
SJw2mTk3EeX14TkgOj/XGdHnefSCkyJhAVnBG0rOFcRj/c/2Zx+ACDNsy3dMtVYH</CipherValue>
 </CipherData>
</EncryptedData>
template.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
XML Security Library example: Original XML
 doc file before encryption (encrypt3 example).
-->
<EncryptedData
  xmlns="http://www.w3.org/2001/04/xmlenc#"
  Type="http://www.w3.org/2001/04/xmlenc#Element">
 <EncryptionMethod Algorithm=
   "http://www.w3.org/2001/04/xmlenc#tripledes-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#">
    <KeyName/>
   </KeyInfo>
   <CipherData>
    <CipherValue/>
   </CipherData>
  </EncryptedKey>
 </KeyInfo>
 <CipherData>
  <CipherValue/>
 </CipherData>
</EncryptedData>
Step 4:

Decrypt XML file using private key.

xmlsec decrypt --privkey-pem books-pri.pem books-enc.xml > books-dec.xml


books-dec.xml:
<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies,
      an evil sorceress, and her own childhood to become queen
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology
      society in England, the young survivors lay the
      foundation for a new society.</description>
   </book>
   <book id="bk104">
      <author>Corets, Eva</author>
      <title>Oberon's Legacy</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-03-10</publish_date>
      <description>In post-apocalypse England, the mysterious
      agent known only as Oberon helps to create a new life
      for the inhabitants of London. Sequel to Maeve
      Ascendant.</description>
   </book>
   <book id="bk105">
      <author>Corets, Eva</author>
      <title>The Sundered Grail</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-09-10</publish_date>
      <description>The two daughters of Maeve, half-sisters,
      battle one another for control of England. Sequel to
      Oberon's Legacy.</description>
   </book>
   <book id="bk106">
      <author>Randall, Cynthia</author>
      <title>Lover Birds</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-09-02</publish_date>
      <description>When Carla meets Paul at an ornithology
      conference, tempers fly as feathers get ruffled.</description>
   </book>
   <book id="bk107">
      <author>Thurman, Paula</author>
      <title>Splish Splash</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>A deep sea diver finds true love twenty
      thousand leagues beneath the sea.</description>
   </book>
   <book id="bk108">
      <author>Knorr, Stefan</author>
      <title>Creepy Crawlies</title>
      <genre>Horror</genre>
      <price>4.95</price>
      <publish_date>2000-12-06</publish_date>
      <description>An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.</description>
   </book>
   <book id="bk109">
      <author>Kress, Peter</author>
      <title>Paradox Lost</title>
      <genre>Science Fiction</genre>
      <price>6.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems
      of being quantum.</description>
   </book>
   <book id="bk110">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in
      detail in this deep programmer's reference.</description>
   </book>
   <book id="bk111">
      <author>O'Brien, Tim</author>
      <title>MSXML3: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in
      detail, with attention to XML DOM interfaces, XSLT processing,
      SAX and more.</description>
   </book>
   <book id="bk112">
      <author>Galos, Mike</author>
      <title>Visual Studio 7: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>49.95</price>
      <publish_date>2001-04-16</publish_date>
      <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are
      integrated into a comprehensive development
      environment.</description>
   </book>
</catalog>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.