Encrypt Decrypt using the Rijndael 256 Mcrypt Function in PHP
You can encrypt and decrypt data using the Mcrypt function below:
<?
$mykey = "THISisMyKey";
function linencrypt($pass)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); //get vector size on ECB mode
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); //Creating the vector
$cryptedpass = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $mykey, $pass, MCRYPT_MODE_ECB, $iv); //Encrypting using MCRYPT_RIJNDAEL_256 algorithm
return $cryptedpass;
}
function lindecrypt($enpass)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decryptedpass = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $mykey, $enpass, MCRYPT_MODE_ECB, $iv); //Decrypting...
return rtrim($decryptedpass);
}
// Calling the functions
$Str_Test="This is a test";
echo("<b>Text</b>: $Str_Test <br><br>");
$Str_Test2 = linencrypt($Str_Test);
echo("<b>Encrypted</b>: $Str_Test2 <br><br>");
$Str_Test3 = lindecrypt($Str_Test2);
echo("<b>Decrypted</b>: $Str_Test3 <br>");
?>
Related Articles
- Add an Automatic / Dynamic Copyrighted Year Message in PHP
- Php Mail Function with Html Header
- How to check if an email address exists without sending an email?
- Pass Array from Multipart/Form-data Post Method or Query String with Foreach Function in PHP
- Use in_array function to check if a value exists in an array using PHP
- Loop through an Array using Foreach Function in PHP
- Delete File or an Image from the Server using PHP
- Encrypt Decrypt using the Rijndael 256 Mcrypt Class in PHP
