src/Security/Encryption.php
public function encrypt($value)
    {
        /**
         * Gets the cipher iv length.
         */
        $iv = random_bytes(openssl_cipher_iv_length($this->cipher));

        /**
         * Encrypts the given value.
         */
        $value = \openssl_encrypt($value, $this->cipher, $this->key, 0, $iv);

        $hash_mac = $this->mac($iv = base64_encode($iv), $value);

        if (!$value) {
            throw new Exception('Unable to encrypt given value');
        }

        $encrypted = json_encode(compact('iv', 'value', 'hash_mac'));

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new Exception('Unable to encrypt given value.');
        }

        return base64_encode($encrypted);
    }
public function encrypt($value)
    {
        /**
         * Gets the cipher iv length.
         */
        $iv = random_bytes(openssl_cipher_iv_length($this->cipher));

        /**
         * Encrypts the given value.
         */
        $value = \openssl_encrypt($value, $this->cipher, $this->key, 0, $iv);

        $hash_mac = $this->mac($iv = base64_encode($iv), $value);

        if (!$value) {
            throw new Exception('Unable to encrypt given value');
        }

        $encrypted = json_encode(compact('iv', 'value', 'hash_mac'));

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new Exception('Unable to encrypt given value.');
        }

        return base64_encode($encrypted);
    }
public function encrypt ( $ value ) { /**
         * Gets the cipher iv length.
         */ $ iv = random_bytes ( openssl_cipher_iv_length ( $ this -> cipher ) ) ; /**
         * Encrypts the given value.
         */ $ value = \ openssl_encrypt ( $ value , $ this -> cipher , $ this -> key , 0 , $ iv ) ; $ hash_mac = $ this -> mac ( $ iv = base64_encode ( $ iv ) , $ value ) ; if ( ! $ value ) { throw new Exception ( 'Unable to encrypt given value' ) ; } $ encrypted = json_encode ( compact ( 'iv' , 'value' , 'hash_mac' ) ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new Exception ( 'Unable to encrypt given value.' ) ; } return base64_encode ( $ encrypted ) ; }
Encrypt the value.

@param $value

@throws Exception

@return string
Encrypt the value .