WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Encrypt/Decrypt
Categories : PHP, Encryption Click here to Update Your Picture
Alix Axel
Date : Nov 22nd 2008
Grade : 3 of 5 (graded 2 times)
Viewed : 1499
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Alix Axel
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

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



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
How to get the source of a site into an array.
Categories : Arrays, HTML, PHP
calculus of the eastersunday
Categories : BC math, PHP, Date Time, Databases
Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June).
Categories : Calendar, Date Time, PHP
Classic guest book made with PHP and Flash
Categories : PHP, Flash, Java Script
PHPShell - A class implementing a shell written in PHP
Categories : PHP, PHP Classes, CLI
Render TTF Text to PNG. Text message, font, size, rotation, padding, color, background, and transparency can all be defined via URL.
Categories : PHP, PHP Classes, Graphics
php Free chat simple fast and customizable chat server that uses a simple filesystem for message and nickname storage
Categories : PHP, AJAX, XML, Complete Programs