Skip to content

Instantly share code, notes, and snippets.

@RDelorier
Last active January 20, 2016 17:00

Revisions

  1. RDelorier revised this gist Jan 20, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion encrypt.php
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    *
    * @return string
    */
    private function encrypt($value)
    function encrypt($value)
    {
    $key = 'secret-key-here';
    $cipher = 'AES-256-CBC';
  2. RDelorier revised this gist Jan 20, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions encrypt.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    /**
    * Encrypts the value in a way compatible with laravel 5.1
    * @param $value value to encrypt
  3. RDelorier created this gist Jan 20, 2016.
    19 changes: 19 additions & 0 deletions encrypt.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    /**
    * Encrypts the value in a way compatible with laravel 5.1
    * @param $value value to encrypt
    *
    * @return string
    */
    private function encrypt($value)
    {
    $key = 'secret-key-here';
    $cipher = 'AES-256-CBC';
    $iv = openssl_random_pseudo_bytes(16);

    $value = openssl_encrypt(serialize($value), $cipher, $key, 0, $iv);
    $iv = base64_encode($iv);
    $mac = hash_hmac('sha256', $iv . $value, $key);
    $json = json_encode(compact('iv', 'value', 'mac'));

    return base64_encode($json);
    }