encrypt and decrypt md5 encrypt and decrypt md5 php php

encrypt and decrypt md5


As already stated, you cannot decrypt MD5 without attempting something like brute force hacking which is extremely resource intensive, not practical, and unethical.

However you could use something like this to encrypt / decrypt passwords/etc safely:

$input = "SmackFactory";$encrypted = encryptIt( $input );$decrypted = decryptIt( $encrypted );echo $encrypted . '<br />' . $decrypted;function encryptIt( $q ) {    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';    $qEncoded      = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );    return( $qEncoded );}function decryptIt( $q ) {    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';    $qDecoded      = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");    return( $qDecoded );}

Using a encypted method with a salt would be even safer, but this would be a good next step past just using a MD5 hash.


There is no way to decrypt MD5. Well, there is, but no reasonable way to do it. That's kind of the point.

To check if someone is entering the correct password, you need to MD5 whatever the user entered, and see if it matches what you have in the database.


/* you  can match the exact string with table value*/if(md5("string to match") == $res["hashstring"]) echo "login correct";