0

I am sorry for my English.

The project migrates from Node to Laravel.

I'm the junior, maybe someone will tell me the right direction in the search)))

How to decrypt in Laravel what is encrypted in cryptojs?

In Node, they use CryptoJS and worked with passwords like this:

Encrypt

password: cryptojs.encrypt(JSON.stringify(req.body.password), secretKey).toString(),

Decrypt

cryptojs.decrypt(user.password.toString(), secretKey);

I'm trying to implement a password-checking mechanism in Laravel. I have secretKey, old password, db stored data.

Tried this

$newEncrypter = new \Illuminate\Encryption\Encrypter(config('app.secret_key'), config('app.cipher'));
$decrypted = $newEncrypter->decrypt( $encrypted );

tinker output: Illuminate\Contracts\Encryption\DecryptException The payload is invalid.

Tried this and it return false

public function check($value, $hashedValue, array $options = [])
{
   $hashedBytes = base64_decode($hashedValue);
   $iv = substr($hashedBytes, 0, openssl_cipher_iv_length('aes-256-cbc'));
   $encrypted = substr($hashedBytes, openssl_cipher_iv_length('aes-256-cbc'));
   $decrypted = openssl_decrypt($encrypted, 'aes-256-cbc', $this->key, OPENSSL_RAW_DATA, $iv);

   return $value === $decrypted;
}
Mohammad Edris Raufi
  • 1,393
  • 1
  • 13
  • 34
V-E-Y
  • 169
  • 2
  • 5

0 Answers0