What is the difference between bcrypt and encrypt, and how to return value to normal state in laravel?
What is the difference between bcrypt and encrypt, and how to return value to normal state in laravel?
bcrypt() is for creating a Hash, which is a one-way process to turn a plain-text string into a hashed value. You cannot un-hash a value, so there is no way to return the value to it's "normal" state.
encrypt() is for "obfuscation", which changes the plain-text string into a non-human readable value. This is not a one-way process, as decrypt() allows you to get the plain-text value.
Some examples:
bcrypt('password'); // '$2y$10$s8MB0AJsUmUN/NCWqZuDx.KrXXNYw50fFdJWqKR28qoOeMN.Rahfq'
In the above, the string 'password' is transformed into that seemingly random string. There is no way to undo this, which is why hashing is the preferred method for storing sensitive information like passwords. You can compare Hashes to determine if they match, but this requires you to explicitly know the original value:
Hash::compare('12345678', bcrypt('password')); // false
Hash::compare('password', bcrypt('password')); // true
As for encryption:
$encrypted = encrypt('password'); // 'eyJpdiI6Im9uQ1M0NDNhcXBWdnJ1azBXWDQwMlE9PSIsInZhbHVlIjoiZmxrcGRNVGY3MnIzbVhkMmsyQzNVUT09IiwibWFjIjoiMTViZWVjMWJiYTAzZTNiNTc3YzljNmMwMjI5ZTBmZjc3M2UyN2EwOGZhMWFiOTg5MDY2NDY1Y2QwZjRmZTgyNSJ9'
$decrypted = decrypt($encrypted); // 'password'
As you can see, it's trivial to decrypt an encrypted value. This method is useful for hiding non-sensitive information, but should never be used to store sensitive information.