php - encrypt string through url and retrieve on next page? -


i using following php script encrypt string when pass through url.

the majority of code stored in encryption.php file.

encryption.php:

<?php class encryption{     private $config;      public function __construct( $options=array() ){         $this->config=array_merge(             array(                 'cipher'    =>  mcrypt_rijndael_256,                 'mode'      =>  mcrypt_mode_ecb,                 'key'       =>  false,                 'iv'        =>  false,                 'size'      =>  false,                 'base64'    =>  true,                 'salt'      =>  false             ),             $options         );     }     private function getivs( $config=object ){         $config->size=mcrypt_get_iv_size( $config->cipher, $config->mode );         $config->iv=mcrypt_create_iv( $config->size, mcrypt_rand );     }     public function encrypt( $data=null ){         $config=(object)$this->config;         $this->getivs( $config );         $data=trim( $data );         $module = mcrypt_module_open( $config->cipher, '', $config->mode, '' );         mcrypt_generic_init( $module, $config->key, $config->iv );          $output = $config->base64 ? base64_encode( mcrypt_generic( $module, $data ) ) : mcrypt_generic( $module, $data );          mcrypt_generic_deinit( $module );         mcrypt_module_close( $module );         return $output;     }     public function decrypt( $data=null ){         $config=(object)$this->config;         $this->getivs( $config );         mb_detect_order( 'auto' );         $encoding=mb_detect_encoding( $data );         if( !$data or is_null( $data ) or empty( $data ) or !$encoding or $data=='' or base64_decode( $data )=='' ) return false;          $module = mcrypt_module_open( $config->cipher, '', $config->mode, '' );         mcrypt_generic_init( $module, $config->key, $config->iv );          $output = $config->base64 ? rtrim( mdecrypt_generic( $module, base64_decode( $data ) ),"\0" ) : rtrim( mdecrypt_generic( $module, $data ),"\0" );          mcrypt_generic_deinit( $module );         mcrypt_module_close( $module );         return urldecode( $output );     } }//end class  ?> 

i call function , pass string encrypted string through url in track_request.php file:

require_once 'dependables/encryption.php';         $string = 'ns' . substr( md5(rand()), 0, 7);         $enc=new encryption( array( 'key'=>'plowfish' ) );         $encrypted_string = $enc->encrypt( $string );           echo '<a href="ns_application.php?ns_request='.$encrypted_string.'">click</a> 

lastly retrieve encrypted string , decrypt again on ns_application.php page:

require_once 'dependables/encryption.php'; $reference = isset($_get['ns_request']) ? $_get['ns_request'] : null; $enc=new encryption( array( 'key'=>'plowfish' ) );  $decrypted_string=$enc->decrypt( $reference ); ?>   <?php echo $decrypted_string; ?> 

the problem script works 5 times out of 10, , end decrypted string looks 'ns1h57347' or 'ns197g347' , on , on etc.

however other 5 times fail , won't decrypt @ end long encrypted string like: 'fjqru248t\£$90=}\31232hgfd*,^='

please can show me going wrong? thanks


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -