7

I have to convert my hash password into string.

here is my code.

<?php namespace App\Http\Controllers;
     use DB;
     use Auth;
     use Input;
     use Session;
     use Route;
     use Crypt;
     use Redirect;
     use Illuminate\Http\Request;
     use Illuminate\Http\Dispatcher; 

      $userdata = array(
                'email'     => $email,
                'password'  =>  Crypt::decrypt($password)
            );

when i use Crypt::decrypt i get error . error-

DecryptException in BaseEncrypter.php line 45:
The payload is invalid.

Can any one suggest me how can i do that?

Thanks.

5
  • are you using Crypt::encrypt for encryption? Commented Oct 5, 2015 at 6:32
  • 3
    Crypto hashes are one-way functions, in that given a hash, it is practically impossible to get back the original text. See more here: en.wikipedia.org/wiki/Cryptographic_hash_function
    – Ermir
    Commented Oct 5, 2015 at 6:33
  • 1
    Password string MUST be NOT DECRYPTABLE! Otherwise it's same as keeping password in plain text.
    – Justinas
    Commented Oct 5, 2015 at 6:35
  • you can use Crypt::decrypt only on the strings which are encrypted using crypt::encrypt, so my suggesting is encrypt password using Crypt::encrypt Commented Oct 5, 2015 at 6:35
  • @Akshay I'm not using Crypt::encrypt . Commented Oct 5, 2015 at 6:35

1 Answer 1

13

Use Crypt::decrypt()

$value = Crypt::decrypt($encrypted);

Note : You must decrypt the value with the same key used to encrypt it.

Laravel's encryption routines use Config::get('app.key') for encryption. This happens internally. Since this value is different for every Laravel application then the application that encrypts a value must also decrypt the value.

Or ...

The application must call Crypt::setKey() prior to decrypting to match the key to the value used for encrypting. See Setting the Encryption Key.

To Encryption use

Crypt::setKey($key);

This key will be used for subsequent Crypt::encrypt() and Crypt::decrypt() calls.

6
  • Thanks Abdulla It is possible to Use Crypt::decrypt(); because i got error when i used like that. Commented Oct 5, 2015 at 6:42
  • So that you have to Encrypt the value Commented Oct 5, 2015 at 6:43
  • 1
    as per my knowledge in Laravel 5.1, support for Crypt::setKey has been dropped @Abdulla Commented Oct 5, 2015 at 6:47
  • 2
    Thanks every one . now i use Crypt::encrypt($password) for encrypt my password when user registration and convert into descrypt with Crypt::decrypt($userdata['password']); i finally i got my descrypt password. Commented Oct 5, 2015 at 6:56
  • 1
    Got this working, except you need to make the saved value a longtext in the database =) #forfurtherreaders Commented Jan 4, 2016 at 10:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.