Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php md5 hashing

Posted on 2011-03-14
8
Medium Priority
?
549 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 400 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1200 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 34

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 111

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

916 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