Encrypt and decrypt md5

I use the code $enrypt=md5($pass) and insert $encrypt into the database. I want to learn how to decrypt them. I tried using decryption software, but it says the hash should be exactly 16 bytes. is there any way to decrypt it or make it a 16 byte md5 hash?

My hash looks like this: c4ca4238a0b923820dcc

+52
security php passwords hash md5
Mar 04 '13 at 4:40
source share
6 answers

As already mentioned, you cannot decrypt MD5 without attempting something like hacking brute force, which is extremely resource-intensive, impractical and unethical.

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

 $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 the encypted salt method would be even safer, but that would be a good next step after using the MD5 hash.

+59
Mar 04 '13 at 5:02
source share

Unable to decrypt MD5. Well, there is, but there is no reasonable way to do this. That kind of point.

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

+14
Mar 04 '13 at 4:43
source share
 /* you can match the exact string with table value*/ if(md5("string to match") == $res["hashstring"]) echo "login correct"; 
+5
Oct 27 '13 at 15:19
source share

This question is tagged by PHP. But many people now use Laravel. This may help someone in the future. That is why I am responsible for Laravel. Easier to encrypt and decrypt using internal functions.

 $string = 'c4ca4238a0b923820dcc'; $encrypted = \Illuminate\Support\Facades\Crypt::encrypt($string); $decrypted_string = \Illuminate\Support\Facades\Crypt::decrypt($encrypted); var_dump($string); var_dump($encrypted); var_dump($decrypted_string); 

Note. Be sure to set a random string of 16, 24 or 32 characters to the key version of the config / app.php file. Otherwise, encrypted values โ€‹โ€‹will not be secure.

But you should not use encryption and decryption for authentication. Rather, you should use a hash code and check.

To save the password in the database, enter the password hash and then save.

 $password = Input::get('password_from_user'); $hashed = Hash::make($password); // save $hashed value 

To verify the password, enter the password from the database

 // $user is database object // $inputs is Input from user if( \Illuminate\Support\Facades\Hash::check( $inputs['password'], $user['password']) == false) { // Password is not matching } else { // Password is matching } 
+3
Jan 30 '16 at 10:22
source share

Hashes cannot be decrypted to verify this .

If you want to encrypt-decrypt, use the two-way encryption function of your database, for example AES_ENCRYPT (in MySQL).

But I will suggest the CRYPT_BLOWFISH algorithm for storing a password. Read this http://php.net/manual/en/function.crypt.php and http://us2.php.net/manual/en/function.password-hash.php

For Blowfish crypt() function -

 crypt('String', '$2a$07$twentytwocharactersalt$'); 



password_hash will be introduced in PHP 5.5.

 $options = [ 'cost' => 7, 'salt' => 'BCryptRequires22Chrcts', ]; password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options); 

After you have saved the password, you can check if the user entered the correct password by associating it again and comparing it with the saved value.

+2
Mar 04 '13 at 4:54 on
source share

Unable to decrypt the generated MD5 hash. To decrypt the MD5 value that was used during encryption, you need all the information.

You can use AES algorithm for encryption and decryption

JavaScript AES encryption and decryption (Advanced Encryption Standard)

+2
Aug 03 '18 at 7:32
source share



All Articles