Solved

php md5 hashing

Posted on 2011-03-14
8
516 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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 110

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 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 110

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

752 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