<?php 
 
/*
 
 +-----------------------------------------------------------------------+
 
 | This file is part of API5 RESTful SQLtoJSON                           |
 
 | Copyright (C) 2007-2018, Santo Nuzzolillo                             |
 
 |                                                                       |
 
 | Licensed under the GNU General Public License version 3 or            |
 
 | any later version with exceptions for skins & plugins.                |
 
 | See the LICENSE file for a full license statement.                    |
 
 |                                                                       |
 
 | Pduction                                                              |
 
 |   Date   : 02/12/2018                                                 |
 
 |   Time   : 05:30:44 PM                                                |
 
 |   Version: 0.0.1                                                      |
 
 +-----------------------------------------------------------------------+
 
 | Author: Santo Nuzzolilo <[email protected]>                       |
 
 +-----------------------------------------------------------------------+
 
*/
 
 
 error_reporting(E_ALL);?> 
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>CryptoJS AES and PHP</title> 
<script type="text/javascript" src="aes.js"></script> 
<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="../aes-json-format.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $(".decrypt").on("click", function(){ 
        $(this).prev().val(JSON.parse(CryptoJS.AES.decrypt($(".encrypted").val(), $(document.e).find(".pass").val(), {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8))); 
    }); 
}); 
</script> 
</head> 
<body> 
<h1>CryptoJS AES and PHP</h1> 
 
<h2>Example to encrypt with PHP on serverside side and decrypt on client side</h2> 
<form name="e" method="post" action=""> 
    Value to encrypt: <input type="text" name="val" value="<?php 
 
/*
 
 +-----------------------------------------------------------------------+
 
 | This file is part of API5 RESTful SQLtoJSON                           |
 
 | Copyright (C) 2007-2018, Santo Nuzzolillo                             |
 
 |                                                                       |
 
 | Licensed under the GNU General Public License version 3 or            |
 
 | any later version with exceptions for skins & plugins.                |
 
 | See the LICENSE file for a full license statement.                    |
 
 |                                                                       |
 
 | Pduction                                                              |
 
 |   Date   : 02/12/2018                                                 |
 
 |   Time   : 05:30:44 PM                                                |
 
 |   Version: 0.0.1                                                      |
 
 +-----------------------------------------------------------------------+
 
 | Author: Santo Nuzzolilo <[email protected]>                       |
 
 +-----------------------------------------------------------------------+
 
*/
 
 
 echo isset($_POST["val"]) ? $_POST["val"] : "My string - Could also be an JS array/object"?>" class="val" size="45"/><br/> 
    Passphrase: <input type="text" name="pass" class="pass" value="<?php 
 
/*
 
 +-----------------------------------------------------------------------+
 
 | This file is part of API5 RESTful SQLtoJSON                           |
 
 | Copyright (C) 2007-2018, Santo Nuzzolillo                             |
 
 |                                                                       |
 
 | Licensed under the GNU General Public License version 3 or            |
 
 | any later version with exceptions for skins & plugins.                |
 
 | See the LICENSE file for a full license statement.                    |
 
 |                                                                       |
 
 | Pduction                                                              |
 
 |   Date   : 02/12/2018                                                 |
 
 |   Time   : 05:30:44 PM                                                |
 
 |   Version: 0.0.1                                                      |
 
 +-----------------------------------------------------------------------+
 
 | Author: Santo Nuzzolilo <[email protected]>                       |
 
 +-----------------------------------------------------------------------+
 
*/
 
 
 echo isset($_POST["pass"]) ? $_POST["pass"] : "my secret passphrase"?>" size="45"/><br/> 
    <input type="submit" name="encrypt" value="Send to server and encrypt, than decrypt with cryptoJS"/> 
    <?php 
 
/*
 
 +-----------------------------------------------------------------------+
 
 | This file is part of API5 RESTful SQLtoJSON                           |
 
 | Copyright (C) 2007-2018, Santo Nuzzolillo                             |
 
 |                                                                       |
 
 | Licensed under the GNU General Public License version 3 or            |
 
 | any later version with exceptions for skins & plugins.                |
 
 | See the LICENSE file for a full license statement.                    |
 
 |                                                                       |
 
 | Pduction                                                              |
 
 |   Date   : 02/12/2018                                                 |
 
 |   Time   : 05:30:44 PM                                                |
 
 |   Version: 0.0.1                                                      |
 
 +-----------------------------------------------------------------------+
 
 | Author: Santo Nuzzolilo <[email protected]>                       |
 
 +-----------------------------------------------------------------------+
 
*/
 
 
 
    if(isset($_POST["encrypt"])){ 
        include("../cryptojs-aes.php"); 
        ?> 
        <hr/> 
        <br/><br/> 
        Encrypted value generated by PHP: <input type="text" value="<?php 
 
/*
 
 +-----------------------------------------------------------------------+
 
 | This file is part of API5 RESTful SQLtoJSON                           |
 
 | Copyright (C) 2007-2018, Santo Nuzzolillo                             |
 
 |                                                                       |
 
 | Licensed under the GNU General Public License version 3 or            |
 
 | any later version with exceptions for skins & plugins.                |
 
 | See the LICENSE file for a full license statement.                    |
 
 |                                                                       |
 
 | Pduction                                                              |
 
 |   Date   : 02/12/2018                                                 |
 
 |   Time   : 05:30:44 PM                                                |
 
 |   Version: 0.0.1                                                      |
 
 +-----------------------------------------------------------------------+
 
 | Author: Santo Nuzzolilo <[email protected]>                       |
 
 +-----------------------------------------------------------------------+
 
*/
 
 
 echo htmlentities(cryptoJsAesEncrypt($_POST["pass"], $_POST["val"]))?>" size="90" disabled="disabled" class="encrypted"/><br/> 
        Decrypted value: <input type="text" value="" size="90" disabled="disabled"/> <input class="decrypt" type="button" value="Decrypt now with cryptoJS"/> 
        <?php 
 
/*
 
 +-----------------------------------------------------------------------+
 
 | This file is part of API5 RESTful SQLtoJSON                           |
 
 | Copyright (C) 2007-2018, Santo Nuzzolillo                             |
 
 |                                                                       |
 
 | Licensed under the GNU General Public License version 3 or            |
 
 | any later version with exceptions for skins & plugins.                |
 
 | See the LICENSE file for a full license statement.                    |
 
 |                                                                       |
 
 | Pduction                                                              |
 
 |   Date   : 02/12/2018                                                 |
 
 |   Time   : 05:30:44 PM                                                |
 
 |   Version: 0.0.1                                                      |
 
 +-----------------------------------------------------------------------+
 
 | Author: Santo Nuzzolilo <[email protected]>                       |
 
 +-----------------------------------------------------------------------+
 
*/
 
 
 
    } 
    ?> 
</form> 
 
</body> 
</html> 
 
 |