|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
These functions allow you to easily encrypt and decrypt text using the mcrypt PHP extension (required) and the Blowfish encryption algorithm.
|
<?php
function Encrypt_Helper($string, $key)
{
if (extension_loaded('mcrypt') === true)
{
return base64_encode(mcrypt_encrypt(MCRYPT_BLOWFISH, substr($key, 0, mcrypt_get_key_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB)), trim($string), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
return false;
}
function Decrypt_Helper($string, $key)
{
if (extension_loaded('mcrypt') === true)
{
return trim(mcrypt_decrypt(MCRYPT_BLOWFISH, substr($key, 0, mcrypt_get_key_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB)), base64_decode($string), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
return false;
}
?> | |
Usage example
| <?php
// returns "K9e+8tesCIziQfNH1QFAsQ=="
echo Encrypt_Helper('top secret info', 'this is the password');
// returns "top secret info"
echo Decrypt_Helper('K9e+8tesCIziQfNH1QFAsQ==', 'this is the password');
?> | | |
|
| PHP Cookies - Simple cookie write/read methods that allow basic encryption Categories : PHP, Cookies, Security, Encryption | | | base64 with encryption - encode and decode sessions Categories : PHP, PHP Classes, Encryption, Sessions | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Scramble Eggs - php class to scramble/encode Categories : PHP, PHP Classes, Security, Encryption | | | PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character. Categories : PHP, Algorithms, Security, Authentication, Encryption | | | MD5 based block cypher in 128 bit CFB Categories : PHP, Encryption, MD5 | | | A PHP function to encrypt and decrypt a number or string or a combination of the two. Categories : PHP, Encryption, Security | | | Encrypt/Decrypt string with a given key by using mcrypt module of PHP (suitable to store encrypted data into any type of databases). Categories : PHP, Encryption | | | JDToGregorian -- Converts Julian Day Count to Gregorian date Categories : PHP, PHP Functions, Calendar | | | Encoding data using PGP via PHP's proc_* functions Categories : Cryptography, Security, Email, PHP, PGP | | | Variable serialization and unserialization. Loading and saving variable structures
to and from file. Categories : Arrays, Filesystem, Variables, Strings, PHP | | | Free PDF file creation using PHP. Categories : PDF, PHP | | | How to get the name of the user which is accessing
the current script. Categories : Environment Variables, PHP | | | PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL | | | Latitude-Longitude to Miles Categories : PHP, Utilities, Math. | |
|
|