PsychoticDude85
01-13-2006, 01:35 PM
First random function I decided to give out. Hope it helps those who just use md5(), this makes a more secure base for you to work on. There is a long explanation at the bottom for those who need it.
<?php
/*
### NAME: Encrpytion Function by Alex Elliott
### DESCRIPTION: Encrypts a string into a complicated hash, a very tough result when MHash is available.
### WEBSITE: http://alex-elliott.com/
*/
function encryptData($string,$type) {
if($type == 'SHA256') // See if they have selected to use SHA256 encryption.
{
// Use MHash to encrypt the string with SHA256.
$encryptedstring = bin2hex(mhash(MHASH_SHA256,$string));
echo $encryptedstring;
}
else
{
if($type == 'SHA1') // See if they have selected to use SHA1 encryption.
{
// Encrypt the string with md5, sha1 and base64
$encryptedstring = sha1(base64_encode($string));
echo $encryptedstring;
}
else
{
if($type == 'MD5') // See if they have selected to use MD5 encrpytion.
{
// Encrypt with md5 and base64.
$encryptedstring = md5(base64_encode($string));
echo $encryptedstring;
}
else
{
// If the $type variable is incorrect echo an error.
echo 'You have not specified a valid encryption method. Those available are SHA256, SHA1 and MD5, note the capitals, they are required.';
}
}
}
}
?>
This function can either be simplified to one type if you wish to use it personally. Or as I am planning to use it, you may decide to put it out as it is, with a variable to define the path it chooses so it can be put to use on a variety of platforms.
To use it simply put: encryptData($string,$type); or if you do not wish to use variables: encryptData('this will be encrypted','SHA1');.
<?php
/*
### NAME: Encrpytion Function by Alex Elliott
### DESCRIPTION: Encrypts a string into a complicated hash, a very tough result when MHash is available.
### WEBSITE: http://alex-elliott.com/
*/
function encryptData($string,$type) {
if($type == 'SHA256') // See if they have selected to use SHA256 encryption.
{
// Use MHash to encrypt the string with SHA256.
$encryptedstring = bin2hex(mhash(MHASH_SHA256,$string));
echo $encryptedstring;
}
else
{
if($type == 'SHA1') // See if they have selected to use SHA1 encryption.
{
// Encrypt the string with md5, sha1 and base64
$encryptedstring = sha1(base64_encode($string));
echo $encryptedstring;
}
else
{
if($type == 'MD5') // See if they have selected to use MD5 encrpytion.
{
// Encrypt with md5 and base64.
$encryptedstring = md5(base64_encode($string));
echo $encryptedstring;
}
else
{
// If the $type variable is incorrect echo an error.
echo 'You have not specified a valid encryption method. Those available are SHA256, SHA1 and MD5, note the capitals, they are required.';
}
}
}
}
?>
This function can either be simplified to one type if you wish to use it personally. Or as I am planning to use it, you may decide to put it out as it is, with a variable to define the path it chooses so it can be put to use on a variety of platforms.
To use it simply put: encryptData($string,$type); or if you do not wish to use variables: encryptData('this will be encrypted','SHA1');.