Solved

php md5 hashing

Posted on 2011-03-14
8
523 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

623 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