Skip to content

Instantly share code, notes, and snippets.

@erlangparasu
Last active June 27, 2020 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erlangparasu/53936f3f9eddb9edc07c6d927bc86cdb to your computer and use it in GitHub Desktop.
Save erlangparasu/53936f3f9eddb9edc07c6d927bc86cdb to your computer and use it in GitHub Desktop.
<?php
namespace App\Providers;
// ...
class AppServiceProvider extends ServiceProvider
{
// ...
public static function createEncrypter($key32)
{
return new \Illuminate\Encryption\Encrypter($key32, 'AES-256-CBC');
}
}
@erlangparasu
Copy link
Author

erlangparasu commented Jun 27, 2020

$encrypter = AppServiceProvider::createEncrypter($key = \Str::random(32));
$encrypted_data = $encrypter->encrypt('mySecretData');
$decrypted_data = $encrypter->decrypt($encrypted_data); // "mySecretData"

$encrypter = AppServiceProvider::createEncrypter($key);
$decrypted_data = $encrypter->decrypt($encrypted_data); // "mySecretData"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment