master

laravel/framework

Last updated at: 29/12/2023 09:21

Encrypter.php

TLDR

The Encrypter.php file in the Illuminate\Contracts\Encryption namespace defines an interface for encrypting and decrypting values using an encryption key.

Methods

encrypt

This method is used to encrypt a given value. It takes two arguments: $value and $serialize. The $value parameter represents the value to be encrypted, while the $serialize parameter is a boolean indicating whether the value should be serialized before encryption. The method returns the encrypted value as a string. If an error occurs during encryption, it throws an EncryptException exception.

decrypt

This method is used to decrypt a given encrypted value. It takes two arguments: $payload and $unserialize. The $payload parameter represents the encrypted value to be decrypted, while the $unserialize parameter is a boolean indicating whether the decrypted value should be unserialized. The method returns the decrypted value. If an error occurs during decryption, it throws a DecryptException exception.

getKey

This method is used to retrieve the encryption key currently used by the encrypter. It returns the encryption key as a string.

<?php

namespace Illuminate\Contracts\Encryption;

interface Encrypter
{
    /**
     * Encrypt the given value.
     *
     * @param  mixed  $value
     * @param  bool  $serialize
     * @return string
     *
     * @throws \Illuminate\Contracts\Encryption\EncryptException
     */
    public function encrypt($value, $serialize = true);

    /**
     * Decrypt the given value.
     *
     * @param  string  $payload
     * @param  bool  $unserialize
     * @return mixed
     *
     * @throws \Illuminate\Contracts\Encryption\DecryptException
     */
    public function decrypt($payload, $unserialize = true);

    /**
     * Get the encryption key that the encrypter is currently using.
     *
     * @return string
     */
    public function getKey();
}