Source for file crypt.php
Documentation is available at crypt.php
* @copyright Copyright 2005-2010 RedIRIS, http://www.rediris.es/
* This file is part of phpPoA2.
* phpPoA2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* phpPoA2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with phpPoA2. If not, see <http://www.gnu.org/licenses/>.
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
// RIJNDAEL Crypt Functions (AES)
// Constant to encrypt and decrypt data with openssl
// PHP 5.3 already has this method, for the rest of us (legacy purposes), we
// redefine the method and call
// Please note that papi_openssl_encrypt and papi_openssl_decrypt
// should be used from now on...
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,'');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
if (mcrypt_generic_init($td, $key, $iv) != - 1) {
$crypttext = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
// Encode the encrypted text
// Decode the encrypted text
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,'');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
if (mcrypt_generic_init($td, $key, $iv) != - 1) {
$decrypttext = mdecrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$decrypttext = trim ($decrypttext);
// 3DES Crypt Functions (Not used in phpPoA)
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
if (mcrypt_generic_init($td, $key, $iv) != - 1) {
$crypttext = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
// Encode the encrypted text
// Decode the encrypted text
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
if (mcrypt_generic_init($td, $key, $iv) != - 1) {
$decrypttext = mdecrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$decrypttext = trim ($decrypttext);
// Openssl Crypt Functions (Not used in phpPoA)
//////////////////////////////////////////////////////////////////////////////////////
// Openssl Crypt Functions
//////////////////////////////////////////////////////////////////////////////////////
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// funcion papi_openssl_encrypt (Not used in phpPoA)
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Get the byte size of data string
// Get details of the key
$key_details= array('bits' => $key_bits);
// Get the output block maximun size in Bytes
$outputBlockSize = $key_details['bits']/ 8;
// Total number of blocks
$numBlocks = ceil($inputSize/ $inputBlockSize);
while ($blockCount < $numBlocks) {
$index = $blockCount * $inputBlockSize;
$block = substr($in, $index, $inputBlockSize);
$cryptBuffer[$blockCount] = $crypttext;
// Now joint the array with the blocks string encripted
$cryptData = join("", $cryptBuffer);
// Return the encrypted, joined and base64 encode data string.
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// funcion papi_openssl_decrypt
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Decode the base64 input string
// Get the byte size of data string
// Get details of the key
$key_details= array('bits' => $key_bits);
// Get the output block maximun size in Bytes
$outputBlockSize = $key_details['bits']/ 8;
//$inputBlockSize = $outputBlockSize - PADDINGSIZE;
$inputBlockSize = $outputBlockSize;
$numBlocks = ceil($inputSize/ $inputBlockSize);
$decryptBuffer = array();
while ($blockCount < $numBlocks) {
$index = $blockCount * $inputBlockSize;
$block = substr($in, $index, $inputBlockSize);
$decryptBuffer[$blockCount] = $decrypttext;
// Now joint the array with the blocks string encripted
$decryptData = join("",$decryptBuffer);
// Return the base64 dencode, decrypted and joined data string.
|