Encrypter
class Encrypter implements Encrypter, StringEncrypter
Properties
| protected string | $key | The encryption key. |
|
| protected array | $previousKeys | The previous / legacy encryption keys. |
|
| protected string | $cipher | The algorithm used for encryption. |
Methods
Create a new encrypter instance.
Determine if the given key and cipher combination is valid.
Create a new encryption key for the given cipher.
Encrypt the given value.
Encrypt a string without serialization.
Decrypt the given value.
Decrypt the given string without unserialization.
Create a MAC for the given value.
Get the JSON array from the given payload.
Verify that the encryption payload is valid.
Determine if the MAC for the given payload is valid.
Determine if the MAC is valid for the given payload and key.
Ensure the given tag is a valid tag given the selected cipher.
Determine if we should validate the MAC while decrypting.
Determine if the given value appears to be encrypted by this encrypter.
Get the encryption key that the encrypter is currently using.
Get the current encryption key and all previous encryption keys.
Get the previous encryption keys.
Set the previous / legacy encryption keys that should be utilized if decryption fails.
Details
at line 47
__construct(string $key, string $cipher = 'aes-128-cbc')
Create a new encrypter instance.
at line 62
static bool
supported(string $key, string $cipher)
Determine if the given key and cipher combination is valid.
at line 74
static string
generateKey(string $cipher)
Create a new encryption key for the given cipher.
at line 84
string
encrypt(mixed $value, bool $serialize = true)
Encrypt the given value.
at line 122
string
encryptString(string $value)
Encrypt a string without serialization.
at line 132
mixed
decrypt(string $payload, bool $unserialize = true)
Decrypt the given value.
at line 199
string
decryptString(string $payload)
Decrypt the given string without unserialization.
at line 207
protected string
hash(string $iv, mixed $value, string $key)
Create a MAC for the given value.
at line 217
protected array
getJsonPayload(string $payload)
Get the JSON array from the given payload.
at line 234
protected bool
validPayload(mixed $payload)
Verify that the encryption payload is valid.
at line 256
protected bool
validMac(array $payload)
Determine if the MAC for the given payload is valid.
at line 264
protected bool
validMacForKey(array $payload, string $key)
Determine if the MAC is valid for the given payload and key.
at line 275
protected void
ensureTagIsValid(string|null $tag)
Ensure the given tag is a valid tag given the selected cipher.
at line 289
protected bool
shouldValidateMac()
Determine if we should validate the MAC while decrypting.
at line 297
static bool
appearsEncrypted(mixed $value)
Determine if the given value appears to be encrypted by this encrypter.
at line 318
string
getKey()
Get the encryption key that the encrypter is currently using.
at line 326
array
getAllKeys()
Get the current encryption key and all previous encryption keys.
at line 334
array
getPreviousKeys()
Get the previous encryption keys.
at line 347
Encrypter
previousKeys(array $keys)
Set the previous / legacy encryption keys that should be utilized if decryption fails.
Mutates the previous-key list; the encrypter is registered as a container singleton, so per-request use races across coroutines.