Php encrypt and decrypt

This article will give information about php “encryption” and “decryption”. When we send information from one page to another page via “URL”, Anyone can see what we are sending in url. To avoid that, We will send encrypted message or information. On destination page we will decrypt this text. So it will secure and anyone could not understand. For encryption and decryption, We have to use one keyword. So if anyone will change the input encrypted text, We could not decrypt the text. It is nice one to send message via url

define('KEY', 'MYKEYVALUE'); 

function encrypt($ENTEXT) 
{ 
    return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, KEY,
        $ENTEXT, MCRYPT_MODE_ECB, mcrypt_create_iv(
        mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
                          MCRYPT_RAND)))); 
} 

function decrypt($DETEXT) 
{
    return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, KEY,
       base64_decode($DETEXT), MCRYPT_MODE_ECB, 
       mcrypt_create_iv(mcrypt_get_iv_size( 
                       MCRYPT_RIJNDAEL_256,
                      MCRYPT_MODE_ECB), MCRYPT_RAND))); 
} 

$encryptedmessage = encrypt("your message"); 

echo decrypt($encryptedmessage); 

 

Leave a Reply

Your email address will not be published. Required fields are marked *