Solved

php md5 hashing

Posted on 2011-03-14
8
491 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
 
LVL 108

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 108

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 look for a specific file type in a local or remote server directory using PHP.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now