{"id":36,"date":"2016-05-06T08:52:44","date_gmt":"2016-05-06T08:52:44","guid":{"rendered":"http:\/\/symbioticindia.in\/docu\/?p=36"},"modified":"2016-05-06T08:52:44","modified_gmt":"2016-05-06T08:52:44","slug":"practical-uses-of-client-side-encryption","status":"publish","type":"post","link":"http:\/\/symbioticindia.in\/docu\/2016\/05\/06\/practical-uses-of-client-side-encryption\/","title":{"rendered":"Practical uses of client side encryption"},"content":{"rendered":"<table class=\"contentpaneopen\">\n<tbody>\n<tr>\n<td colspan=\"2\" valign=\"top\"><strong>Important<\/strong> : We&#8217;ve just launched\u00a0 <a href=\"http:\/\/www.userencrypted.com\/\">UserEncrypted.com<\/a> , a free client side encryption service to securely store passwords or notes. The peculiarirty of the system is that your clear data never leaves your browser, and only encrypted data is sent to our server.<\/p>\n<p>I recently happened to work on a web application whose commissioner was a society hosting sensitive data for its customers. Data needed to be accessible only by the respective owner and noone else at any level, database included. The platform was LAMPJ (Linux, Apache,Mysql,PHP and some Java webservices accessed by the PHP layer), and password protected AES encryption was required by the commissioner.<\/p>\n<p><strong>Proposals<\/strong><br \/>\nThe 2 proposed solutions were:<\/p>\n<ol>\n<li>database encryption using mysql aes_encrypt function<\/li>\n<li>client side encryption<\/li>\n<\/ol>\n<p>Database encryption was discarded immediately because the approach would have meant that the PHP level had access to unencrypted data, so only client encryption being left, a second choice needed be done between:<\/p>\n<ol>\n<li>a java applet using the bouncycastle library<\/li>\n<li>pure javascript encryption<\/li>\n<\/ol>\n<p>Although I&#8217;m quite accustomed to encryption, digital signature and timestamping with Java, I (initially) decided, due to strong encryption export issues, to give a try to the Javascript approach. Obviously I wasn&#8217;t going to implement aes in javascript by myself, and found the right code at <a href=\"http:\/\/www.movable-type.co.uk\/scripts\/aes.html\" target=\"_blank\">Movable Type Scripts<\/a>, where you can find the complete source code.<br \/>\nThe code is clear and really easy to use. We have two methods we need to get the work done: <em>AESEncryptCtr<\/em> and <em>AESDecryptCtr<\/em>.<br \/>\n<strong>Practical use<\/strong><br \/>\nAt this point it was just a matter of how to deal with sensitive data.<br \/>\nFor simplicity&#8217;s sake, let&#8217;s imagine an html form with one hidden input field containing encrypted data and a text area for the unencrypted text. On the server side we&#8217;ll keep our data in a plain file.<br \/>\nWe&#8217;re using php, but this doesn&#8217;t affect the result.<br \/>\nOne last thing, to avoid charset or special character problems, we&#8217;ll also base64 encode\/decode the encrypted text, again on the client side. To achieve this we&#8217;ll use <a href=\"http:\/\/rumkin.com\/tools\/compression\/base64.php\" target=\"_blank\">Tyler Akins&#8217;<\/a> javascript code, kindly released to the public domain.<br \/>\nThat said, our files will be:<\/p>\n<ol>\n<li>base64.js &#8211; <a href=\"http:\/\/www.beanizer.org\/demo\/encryption\/base64.js\" target=\"_blank\">here<\/a> are the base64 encoding\/decoding functions<\/li>\n<li>encrypt.js &#8211; <a href=\"http:\/\/www.beanizer.org\/demo\/encryption\/encryption.js\" target=\"_blank\">here<\/a> is code downloaded from <a href=\"http:\/\/www.movable-type.co.uk\/scripts\/aes.html\" target=\"_blank\">Movable Type Scripts<\/a><\/li>\n<li>encrypt.txt &#8211; our content file. It will contain our encrypted data and will be created by the php file<\/li>\n<li>encrypt.php &#8211; here we&#8217;ll (horribly) mix some php code and html<\/li>\n<\/ol>\n<p>And here is the <em>encrypt.php<\/em> code:<\/p>\n<pre><span style=\"color: #f5deb3;\"><span style=\"color: #ffffcc;\">   1:<\/span><span style=\"color: #00aae2;\">&lt;?php<\/span>\r\n<span style=\"color: #ffffcc;\">   2:<\/span>        \r\n<span style=\"color: #ffffcc;\">   3:<\/span>        \r\n<span style=\"color: #ffffcc;\">   4:<\/span>        <span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">filePath<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">_SERVER<\/span><span style=\"color: #00ffff;\">[<\/span><span style=\"color: #00cd00;\">'<\/span><span style=\"color: #00cd00;\">DOCUMENT_ROOT<\/span><span style=\"color: #00cd00;\">'<\/span><span style=\"color: #00ffff;\">]<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">\/<\/span><span style=\"color: #00cd00;\">demo<\/span><span style=\"color: #00cd00;\">\/<\/span><span style=\"color: #00cd00;\">encryption<\/span><span style=\"color: #00cd00;\">\/<\/span><span style=\"color: #00cd00;\">encryption<\/span><span style=\"color: #00cd00;\">.<\/span><span style=\"color: #00cd00;\">txt<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #00cd00;\">   5:<\/span>        <span style=\"color: #ffa500;\">if<\/span>(<span style=\"color: #ffa500;\">isset<\/span>(<span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">_POST<\/span><span style=\"color: #00ffff;\">[<\/span><span style=\"color: #00cd00;\">'<\/span><span style=\"color: #00cd00;\">encrypted_data<\/span><span style=\"color: #00cd00;\">'<\/span><span style=\"color: #00ffff;\">]<\/span>))<span style=\"color: #00ffff;\">{<\/span>\r\n<span style=\"color: #ffffcc;\">   6:<\/span>                <span style=\"color: #00cc99;\">file_put_contents<\/span>(<span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">filePath<\/span><span style=\"color: #00ffff;\">,<\/span><span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">_POST<\/span><span style=\"color: #00ffff;\">[<\/span><span style=\"color: #00cd00;\">'<\/span><span style=\"color: #00cd00;\">encrypted_data<\/span><span style=\"color: #00cd00;\">'<\/span><span style=\"color: #00ffff;\">]<\/span>)<span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #ffffcc;\">   7:<\/span>        <span style=\"color: #00ffff;\">}<\/span>\r\n<span style=\"color: #ffffcc;\">   8:<\/span>        <span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">text<\/span><span style=\"color: #00ffff;\">=<\/span>(<span style=\"color: #00cc99;\">file_exists<\/span>(<span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">filePath<\/span>)) <span style=\"color: #00ffff;\">?<\/span> <span style=\"color: #00cc99;\">file_get_contents<\/span>(<span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">filePath<\/span>)<span style=\"color: #00ffff;\">:<\/span> <span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #ffffcc;\">   9:<\/span><span style=\"color: #00aae2;\">?&gt;<\/span>\r\n<span style=\"color: #00cd00;\">  10:<\/span><span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">html<\/span><span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  11:<\/span><span style=\"color: #00aae2;\">&lt;script<\/span> <span style=\"color: #00aae2;\">src<\/span><span style=\"color: #00aae2;\">=<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">base64<\/span><span style=\"color: #00cd00;\">.<\/span><span style=\"color: #00cd00;\">js<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00aae2;\">&gt;<\/span><span style=\"color: #00aae2;\">&lt;\/script&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  12:<\/span><span style=\"color: #00aae2;\">&lt;script<\/span> <span style=\"color: #00aae2;\">src<\/span><span style=\"color: #00aae2;\">=<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">encryption<\/span><span style=\"color: #00cd00;\">.<\/span><span style=\"color: #00cd00;\">js<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00aae2;\">&gt;<\/span><span style=\"color: #00aae2;\">&lt;\/script&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  13:<\/span><span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">body<\/span> <span style=\"color: #00aae2;\">onload<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">getPassword<\/span><span style=\"color: #00cd00;\">(<\/span><span style=\"color: #00cd00;\">)<\/span><span style=\"color: #00cd00;\">;<\/span><span style=\"color: #00cd00;\">decryptData<\/span><span style=\"color: #00cd00;\">(<\/span><span style=\"color: #00cd00;\">)<\/span><span style=\"color: #00cd00;\">;<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  14:<\/span>        <span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">form<\/span> <span style=\"color: #00aae2;\">method<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">POST<\/span> <span style=\"color: #00aae2;\">name<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">myform<\/span><span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #00cd00;\">  15:<\/span>                <span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">input<\/span> <span style=\"color: #00aae2;\">type<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">hidden<\/span> <span style=\"color: #00aae2;\">name<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">encrypted_data<\/span> <span style=\"color: #00aae2;\">id<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">encrypted_data<\/span> <span style=\"color: #00aae2;\">value<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00aae2;\">&lt;?php<\/span> <span style=\"color: #ffa500;\">echo<\/span> <span style=\"color: #cc6600;\">$<\/span><span style=\"color: #cc6600;\">text<\/span><span style=\"color: #00ffff;\">;<\/span><span style=\"color: #00aae2;\">?&gt;<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  16:<\/span>        <span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">\/<\/span><span style=\"color: #00aae2;\">form<\/span><span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  17:<\/span>        <span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">textarea<\/span> <span style=\"color: #00aae2;\">id<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">datafield<\/span> <span style=\"color: #00aae2;\">name<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">datafield<\/span> <span style=\"color: #00aae2;\">rows<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">20<\/span> <span style=\"color: #00aae2;\">cols<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">50<\/span><span style=\"color: #00aae2;\">&gt;<\/span><span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">\/<\/span><span style=\"color: #00aae2;\">textarea<\/span><span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  18:<\/span>        <span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">input<\/span> <span style=\"color: #00aae2;\">type<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">button<\/span> <span style=\"color: #00aae2;\">onclick<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">return<\/span> <span style=\"color: #00cd00;\">encryptData<\/span><span style=\"color: #00cd00;\">(<\/span><span style=\"color: #00cd00;\">)<\/span><span style=\"color: #00cd00;\">;<\/span><span style=\"color: #00cd00;\">\"<\/span> <span style=\"color: #00aae2;\">value<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">submit<\/span><span style=\"color: #00cd00;\">\"<\/span> <span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  19:<\/span>        \r\n<span style=\"color: #00cd00;\">  20:<\/span>        \r\n<span style=\"color: #ffffcc;\">  21:<\/span><span style=\"color: #00aae2;\">&lt;script<\/span> <span style=\"color: #00aae2;\">language<\/span><span style=\"color: #00aae2;\">=<\/span><span style=\"color: #00aae2;\">javascript<\/span><span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  22:<\/span>        <span style=\"color: #ffa500;\">var<\/span> <span style=\"color: #00aae2;\">hiddenfield<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">document<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #b2dfee;\">getElementById<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">encrypted_data<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #ffffcc;\">  23:<\/span>        <span style=\"color: #ffa500;\">var<\/span> <span style=\"color: #00aae2;\">textarea<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00aae2;\">document<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #b2dfee;\">getElementById<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">datafield<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #ffffcc;\">  24:<\/span>        <span style=\"color: #ffa500;\">var<\/span> <span style=\"color: #00aae2;\">password<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #00cd00;\">  25:<\/span>        <span style=\"color: #ffa500;\">function<\/span> <span style=\"color: #b2dfee;\">decryptData<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">{<\/span>\r\n<span style=\"color: #ffffcc;\">  26:<\/span>                <span style=\"color: #ffa500;\">if<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00aae2;\">hiddenfield<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #00aae2;\">value<\/span> <span style=\"color: #00ffff;\">!<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #00cd00;\">'<\/span><span style=\"color: #00cd00;\">'<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">{<\/span>\r\n<span style=\"color: #ffffcc;\">  27:<\/span>                        <span style=\"color: #00aae2;\">textarea<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #00aae2;\">value<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #b2dfee;\">AESDecryptCtr<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #b2dfee;\">decode64<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00aae2;\">hiddenfield<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #00aae2;\">value<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">,<\/span> <span style=\"color: #00aae2;\">password<\/span> <span style=\"color: #00ffff;\">,<\/span><span style=\"color: #00aae2;\">128<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #ffffcc;\">  28:<\/span>                <span style=\"color: #00ffff;\">}<\/span>\r\n<span style=\"color: #ffffcc;\">  29:<\/span>        <span style=\"color: #00ffff;\">}<\/span>\r\n<span style=\"color: #00cd00;\">  30:<\/span>        \r\n<span style=\"color: #ffffcc;\">  31:<\/span>        <span style=\"color: #ffa500;\">function<\/span> <span style=\"color: #b2dfee;\">encryptData<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">{<\/span>\r\n<span style=\"color: #ffffcc;\">  32:<\/span>                <span style=\"color: #00aae2;\">hiddenfield<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #00aae2;\">value<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #b2dfee;\">encode64<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #b2dfee;\">AESEncryptCtr<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00aae2;\">textarea<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #00aae2;\">value<\/span><span style=\"color: #00ffff;\">,<\/span> <span style=\"color: #00aae2;\">password<\/span> <span style=\"color: #00ffff;\">,<\/span><span style=\"color: #00aae2;\">128<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #ffffcc;\">  33:<\/span>                <span style=\"color: #00aae2;\">document<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #00aae2;\">forms<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #00aae2;\">myform<\/span><span style=\"color: #00ffff;\">.<\/span><span style=\"color: #b2dfee;\">submit<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #ffffcc;\">  34:<\/span>        <span style=\"color: #00ffff;\">}<\/span>\r\n<span style=\"color: #00cd00;\">  35:<\/span>        \r\n<span style=\"color: #ffffcc;\">  36:<\/span>        <span style=\"color: #ffa500;\">function<\/span> <span style=\"color: #b2dfee;\">getPassword<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">{<\/span>\r\n<span style=\"color: #ffffcc;\">  37:<\/span>                <span style=\"color: #00aae2;\">password<\/span><span style=\"color: #00ffff;\">=<\/span><span style=\"color: #b2dfee;\">prompt<\/span><span style=\"color: #00aae2;\">(<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00cd00;\">Password<\/span><span style=\"color: #00cd00;\">\"<\/span><span style=\"color: #00aae2;\">)<\/span><span style=\"color: #00ffff;\">;<\/span>\r\n<span style=\"color: #ffffcc;\">  38:<\/span>        <span style=\"color: #00ffff;\">}<\/span>\r\n<span style=\"color: #ffffcc;\">  39:<\/span>        \r\n<span style=\"color: #00cd00;\">  40:<\/span><span style=\"color: #00aae2;\">&lt;\/script&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  41:<\/span><span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">\/<\/span><span style=\"color: #00aae2;\">body<\/span><span style=\"color: #00aae2;\">&gt;<\/span>\r\n<span style=\"color: #ffffcc;\">  42:<\/span><span style=\"color: #00aae2;\">&lt;<\/span><span style=\"color: #00aae2;\">\/<\/span><span style=\"color: #00aae2;\">html<\/span><span style=\"color: #00aae2;\">&gt;<\/span> <\/span><\/pre>\n<p>First the php part:<br \/>\nOn line 4 we set the path for the file which will contain our encrypted data on the server( change it to fit your needs). This is the simplest case. A more real world case would be reading\/writing from\/to a database, but this is not influential now.<br \/>\nIn lines 5-8 we check if something has been submitted and eventually save it on our text file.<br \/>\nOn line 8 we read the encrypted text from the file (if some) and put it on our html hidden field(see below).<\/p>\n<p>Now the html\/javascript part.<br \/>\nWe include base64.js and encryption.js , create a form with a hidden field, which will contain incoming\/outgoing encrypted text, and out of the form a textarea for showing\/updating unencrypted text.<\/p>\n<p>As we can see on line 13, when the page is loaded (event <em>onload<\/em>) we first call the <em>getPassword<\/em> function, which prompts for a password, then we call <em>decryptData<\/em>. This will take the value of the hidden field, base64 decode it and , using the provided password, try to decrypt the data and put it in our textarea. The third parameter in AESDecryptCtr is the number of bits of the encryption key (128,192 and 256 are supported).<br \/>\nNow, if we edit the textarea content and push the submit button, the text in the textarea will be encrypted, again using the provided password, base64 encoded and put in the hidden field (by the function <em>encryptData<\/em>). Then the form will be submitted, and so only encrypted text will be sent back to the server (the textarea, containing clear text, is not part of the form, and so it doesn&#8217;t get submitted).<\/p>\n<p>Easy, does it? Just a couple of notes:<br \/>\n1) if your server php version is old, you may not have <em>file_get_contents<\/em> and <em>file_put_contents<\/em> functions available. In this case you can find them in <a href=\"http:\/\/pear.php.net\/package\/PHP_Compat\" target=\"_blank\">this<\/a> PEAR package.<br \/>\n2) Make sure you have write privileges for the text file you&#8217;re going to use.<\/p>\n<p>That&#8217;s all folks.<\/p>\n<p>P.S.: in the end, for my project, the commissioner asked for PKI and smart card certificate encryption, so I had to implement a Java applet using BouncyCastle&#8217;s library and IAIK&#8217;s pkcs11 layer. So now clients can encrypt with the public keys of all those they want to be able to decrypt their data&#8230;..<br \/>\nMaybe I&#8217;ll write about this soon.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"article_seperator\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Important : We&#8217;ve just launched\u00a0 UserEncrypted.com , a free client side encryption service to securely store passwords or notes. The peculiarirty of the system is that your clear data never leaves your browser, and only encrypted data is sent to our server. I recently happened to work on a web application whose commissioner was a ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"http:\/\/symbioticindia.in\/docu\/2016\/05\/06\/practical-uses-of-client-side-encryption\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-encryption","category-php"],"_links":{"self":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":1,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":37,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/36\/revisions\/37"}],"wp:attachment":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}