Solved

php md5 hashing

Posted on 2011-03-14
8
506 Views
Last Modified: 2012-05-11
HI,
Can any one please provide me with good md5 encryption/decryption functions?
I know I can quickly google it but I am looking for more secure/complicated functions. I have somthing like below but cant find the encryption function for this :)
it would be great if some provide me good ones
thanks
function m_decrypt($text)
    {
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
    }
0
Comment
Question by:SameerMirza
8 Comments
 
LVL 12

Expert Comment

by:Avinash Zala
ID: 35127467
just use  md5('your string here').

and md5 can not be decrypted...
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35127503
If you want to do encyption / decryption then look at this code

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_26868583.html?cid=1133#a35068383

There is a working example class that will do it.
0
 
LVL 6

Assisted Solution

by:akajohn
akajohn earned 100 total points
ID: 35127520
Well, some md5 can be reversed. It is not a decryption service and a huge dictionary of a large number of combinations of md5 hashes. YOu could try http://www.freerainbowtables.com/  (There are some others out there, just try google)
If you are hashing a simple password of a couple of alphanumeric characters or characters only, then the rate or decryption is fairly high. However if you are hashing a huge document then decryption is definitely impossible.

A>
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 109

Accepted Solution

by:
Ray Paseur earned 300 total points
ID: 35127846
See if this works for your needs.  You can test it online on my web site here:
http://www.laprbass.com/RAY_encrypt_decrypt.php
<?php // RAY_encrypt_decrypt.php
error_reporting(E_ALL);

// MAN PAGE: http://us.php.net/manual/en/ref.mcrypt.php

class Encryption
{
    protected $eot;
    protected $key;
    protected $ivs;
    protected $iv;

    public function __construct()
    {
        // SET KEY, DELIMITER, INITIALIZATION VECTOR - MUST BE KNOWN TO BOTH PARTS OF THE ALGORITHM
        $this->key = 'quay';
        $this->eot = '___EOT';
        $this->ivs = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
        $this->iv  = mcrypt_create_iv($this->ivs);
    }

    public function Encrypt($text)
    {
        // APPEND END OF TEXT DELIMITER
        $text .= $this->eot;

        // ENCRYPT THE DATA
        $data = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $text, MCRYPT_MODE_ECB, $this->iv);

        // MAKE IT base64() STRING SAFE FOR STORAGE AND TRANSMISSION
        return base64_encode($data);
    }

    public function Decrypt($text)
    {
        // DECODE THE DATA INTO THE BINARY ENCRYPTED STRING
        $text = base64_decode($text);

        // DECRYPT THE STRING
        $data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, $text, MCRYPT_MODE_ECB, $this->iv);

        // REMOVE END OF TEXT DELIMITER
        $data = explode($this->eot, $data);
        return $data[0];
    }
}

// INSTANTIATE THE CLASS
$c = new Encryption();

// INITIALIZE VARS FOR LATER USE IN THE HTML FORM
$encoded = '';
$decoded = '';

// IF ANYTHING WAS POSTED
if (!empty($_POST["clearstring"]))
{
    $encoded = $c->Encrypt($_POST["clearstring"]);
    echo "<br/>{$_POST["clearstring"]} YIELDS ";
    var_dump($encoded);
}

if (!empty($_POST["cryptstring"]))
{
    $decoded = $c->Decrypt($_POST["cryptstring"]);
    echo "<br/>{$_POST["cryptstring"]} YIELDS ";
    var_dump($decoded);
}

// END OF PHP - PUT UP THE FORM
?>
<form method="post">
<input name="clearstring" value="<?php echo $decoded; ?>" />
<input type="submit" value="ENCRYPT" />
<br/>
<input name="cryptstring" value="<?php echo $encoded; ?>" />
<input type="submit" value="DECRYPT" />
</form>

Open in new window

0
 

Assisted Solution

by:SameerMirza
SameerMirza earned 0 total points
ID: 35128267
thanks every one.
@Ray, I found the below easier to implement or may be ur code is similar.
Do you think there is somthnig wrong with implementing/using the below codE? - Just want to make sure
<?php 
    define('SALT', 'whateveryouwant'); 
    
    function encrypt($text) 
    { 
        return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)))); 
    } 

    function decrypt($text) 
    { 
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))); 
    } 
?>

Open in new window

0
 
LVL 33

Expert Comment

by:Slick812
ID: 35132105
greetings SameerMirza, although the code you have in comment ID:35128267 would seem to work for you, you use the  trim( ), which would delete any space charater, if it was at the end of your your string, here some code for a way to avoid that. . .
if you use  rtrim($string, chr(0)) it will not delete a space charater, , also if you are in the MCRYPT_MODE_ECB  , then the mcrypt_encrypt( ) does not need the IV at all, it does not use an IV. I do not need any points, so you do not need to change anything, use my suggestion or not, it does not matter to me.
define('SALT', 'whanmjhyryouwant');

function encrypt($text) 
{
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB)); 
} 
function decrypt($text) 
{
return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, base64_decode($text), MCRYPT_MODE_ECB),chr(0)); 
}

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 35132756
No problem at all.  Best regards, ~Ray
0
 

Author Closing Comment

by:SameerMirza
ID: 35170832
Thanks for the help.
Ray, your solution is acurate but I had to split the points to akajohbn for helping and offcourse to myslef :)
HOpe you can understand
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to use embargo Date/time in php 29 39
Wordpress Taxonomy 2 29
paypal ipn url 5 58
PHP-Client-Registration-Login article and  saving last last login 6 30
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question