---
title: "Phalcon Encryption"
version: "5.20"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.phalcon.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Phalcon Encryption

:::info[NOTE]
All classes are prefixed with `Phalcon`
:::

## Encryption\Crypt

Class

Provides encryption capabilities to Phalcon applications.

```php
use Phalcon\Crypt;

$crypt = new Crypt();

$crypt->setCipher("aes-256-ctr");

$key  =
"T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3";
$input = "The message to be encrypted";

$encrypted = $crypt->encrypt($input, $key);

echo $crypt->decrypt($encrypted, $key);
```

- **`Phalcon\Encryption\Crypt`** - implements [`Phalcon\Encryption\Crypt\CryptInterface`](#encryptioncryptcryptinterface)

`Phalcon\Encryption\Crypt\CryptInterface` · `Phalcon\Encryption\Crypt\Exception\DecryptionFailed` · `Phalcon\Encryption\Crypt\Exception\EmptyDecryptionKey` · `Phalcon\Encryption\Crypt\Exception\EmptyEncryptionKey` · `Phalcon\Encryption\Crypt\Exception\EncryptionFailed` · `Phalcon\Encryption\Crypt\Exception\Exception` · `Phalcon\Encryption\Crypt\Exception\InvalidAuthTagLength` · `Phalcon\Encryption\Crypt\Exception\InvalidDecryptLength` · `Phalcon\Encryption\Crypt\Exception\InvalidPaddingSize` · `Phalcon\Encryption\Crypt\Exception\IvLengthCalculationFailed` · `Phalcon\Encryption\Crypt\Exception\Mismatch` · `Phalcon\Encryption\Crypt\Exception\MissingAuthData` · `Phalcon\Encryption\Crypt\Exception\MissingOpensslExtension` · `Phalcon\Encryption\Crypt\Exception\RandomBytesGenerationFailed` · `Phalcon\Encryption\Crypt\Exception\UnsupportedAlgorithm` · `Phalcon\Encryption\Crypt\PadFactory` · `Phalcon\Traits\Php\Base64Trait` · `Phalcon\Traits\Php\HashTrait` · `Phalcon\Traits\Php\InfoTrait` · `Phalcon\Traits\Php\OpensslTrait`

### Method Summary

<ApiItem href="#encryptioncrypt-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"string","name":"cipher","default":"self::DEFAULT_CIPHER"},{"type":"bool","name":"useSigning","default":"true"},{"type":"PadFactory|null","name":"padFactory","default":"null"}]}>
Crypt constructor.
</ApiItem>
<ApiItem href="#encryptioncrypt-decrypt" visibility="public" name="decrypt" returnType="string" params={[{"type":"string","name":"input","default":null},{"type":"string|null","name":"key","default":"null"}]}>
Decrypts an encrypted text.
</ApiItem>
<ApiItem href="#encryptioncrypt-decryptbase64" visibility="public" name="decryptBase64" returnType="string" params={[{"type":"string","name":"input","default":null},{"type":"string|null","name":"key","default":"null"},{"type":"bool","name":"safe","default":"false"}]}>
Decrypt a text that is coded as a base64 string.
</ApiItem>
<ApiItem href="#encryptioncrypt-encrypt" visibility="public" name="encrypt" returnType="string" params={[{"type":"string","name":"input","default":null},{"type":"string|null","name":"key","default":"null"}]}>
Encrypts a text.
</ApiItem>
<ApiItem href="#encryptioncrypt-encryptbase64" visibility="public" name="encryptBase64" returnType="string" params={[{"type":"string","name":"input","default":null},{"type":"string|null","name":"key","default":"null"},{"type":"bool","name":"safe","default":"false"}]}>
Encrypts a text returning the result as a base64 string.
</ApiItem>
<ApiItem href="#encryptioncrypt-getauthdata" visibility="public" name="getAuthData" returnType="string" params={[]}>
Returns the auth data
</ApiItem>
<ApiItem href="#encryptioncrypt-getauthtag" visibility="public" name="getAuthTag" returnType="string" params={[]}>
Returns the auth tag
</ApiItem>
<ApiItem href="#encryptioncrypt-getauthtaglength" visibility="public" name="getAuthTagLength" returnType="int" params={[]}>
Returns the auth tag length
</ApiItem>
<ApiItem href="#encryptioncrypt-getavailableciphers" visibility="public" name="getAvailableCiphers" returnType="array" params={[]}>
Returns a list of available ciphers.
</ApiItem>
<ApiItem href="#encryptioncrypt-getavailablehashalgorithms" visibility="public" name="getAvailableHashAlgorithms" returnType="array" params={[]}>
Return a list of registered hashing algorithms suitable for hash_hmac.
</ApiItem>
<ApiItem href="#encryptioncrypt-getcipher" visibility="public" name="getCipher" returnType="string" params={[]}>
Returns the current cipher
</ApiItem>
<ApiItem href="#encryptioncrypt-gethashalgorithm" visibility="public" name="getHashAlgorithm" returnType="string" params={[]}>
Get the name of hashing algorithm.
</ApiItem>
<ApiItem href="#encryptioncrypt-getkey" visibility="public" name="getKey" returnType="string" params={[]}>
Returns the encryption key
</ApiItem>
<ApiItem href="#encryptioncrypt-isvaliddecryptlength" visibility="public" name="isValidDecryptLength" returnType="bool" params={[{"type":"string","name":"input","default":null}]}>
Returns if the input length for decryption is valid or not
</ApiItem>
<ApiItem href="#encryptioncrypt-setauthdata" visibility="public" name="setAuthData" returnType="CryptInterface" params={[{"type":"string","name":"data","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncrypt-setauthtag" visibility="public" name="setAuthTag" returnType="CryptInterface" params={[{"type":"string","name":"tag","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncrypt-setauthtaglength" visibility="public" name="setAuthTagLength" returnType="CryptInterface" params={[{"type":"int","name":"length","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncrypt-setcipher" visibility="public" name="setCipher" returnType="CryptInterface" params={[{"type":"string","name":"cipher","default":null}]}>
Sets the cipher algorithm for data encryption and decryption.
</ApiItem>
<ApiItem href="#encryptioncrypt-sethashalgorithm" visibility="public" name="setHashAlgorithm" returnType="static" params={[{"type":"string","name":"hashAlgorithm","default":null}]}>
Set the name of hashing algorithm.
</ApiItem>
<ApiItem href="#encryptioncrypt-setkey" visibility="public" name="setKey" returnType="CryptInterface" params={[{"type":"string","name":"key","default":null}]}>
Sets the encryption key.
</ApiItem>
<ApiItem href="#encryptioncrypt-setpadding" visibility="public" name="setPadding" returnType="CryptInterface" params={[{"type":"int","name":"scheme","default":null}]}>
Changes the padding scheme used.
</ApiItem>
<ApiItem href="#encryptioncrypt-usesigning" visibility="public" name="useSigning" returnType="CryptInterface" params={[{"type":"bool","name":"useSigning","default":null}]}>
Sets if the calculating message digest must used.
</ApiItem>
<ApiItem href="#encryptioncrypt-checkcipherhashisavailable" visibility="protected" name="checkCipherHashIsAvailable" returnType="void" params={[{"type":"string","name":"cipher","default":null},{"type":"string","name":"type","default":null}]}>
Checks if a cipher or a hash algorithm is available
</ApiItem>
<ApiItem href="#encryptioncrypt-cryptpadtext" visibility="protected" name="cryptPadText" returnType="string" params={[{"type":"string","name":"input","default":null},{"type":"string","name":"mode","default":null},{"type":"int","name":"blockSize","default":null},{"type":"int","name":"paddingType","default":null}]}>
Pads texts before encryption. See
</ApiItem>
<ApiItem href="#encryptioncrypt-cryptunpadtext" visibility="protected" name="cryptUnpadText" returnType="string" params={[{"type":"string","name":"input","default":null},{"type":"string","name":"mode","default":null},{"type":"int","name":"blockSize","default":null},{"type":"int","name":"paddingType","default":null}]}>
Removes a padding from a text.
</ApiItem>
<ApiItem href="#encryptioncrypt-decryptgcmccmauth" visibility="protected" name="decryptGcmCcmAuth" returnType="string" params={[{"type":"string","name":"mode","default":null},{"type":"string","name":"cipherText","default":null},{"type":"string","name":"decryptKey","default":null},{"type":"string","name":"iv","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncrypt-decryptgetunpadded" visibility="protected" name="decryptGetUnpadded" returnType="string" params={[{"type":"string","name":"mode","default":null},{"type":"int","name":"blockSize","default":null},{"type":"string","name":"decrypted","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncrypt-encryptgcmccm" visibility="protected" name="encryptGcmCcm" returnType="string" params={[{"type":"string","name":"mode","default":null},{"type":"string","name":"padded","default":null},{"type":"string","name":"encryptKey","default":null},{"type":"string","name":"iv","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncrypt-encryptgetpadded" visibility="protected" name="encryptGetPadded" returnType="string" params={[{"type":"string","name":"mode","default":null},{"type":"string","name":"input","default":null},{"type":"int","name":"blockSize","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncrypt-initializeavailableciphers" visibility="protected" name="initializeAvailableCiphers" returnType="static" params={[]}>
Initialize available cipher algorithms.
</ApiItem>

### Constants

<ApiItem kind="constant" name="DEFAULT_ALGORITHM" type="string" default="&quot;sha256&quot;">
</ApiItem>
<ApiItem kind="constant" name="DEFAULT_CIPHER" type="string" default="&quot;aes-256-cfb&quot;">
</ApiItem>
<ApiItem kind="constant" name="PADDING_ANSI_X_923" type="int" default="1">
Padding
</ApiItem>
<ApiItem kind="constant" name="PADDING_DEFAULT" type="int" default="0">
</ApiItem>
<ApiItem kind="constant" name="PADDING_ISO_10126" type="int" default="3">
</ApiItem>
<ApiItem kind="constant" name="PADDING_ISO_IEC_7816_4" type="int" default="4">
</ApiItem>
<ApiItem kind="constant" name="PADDING_PKCS7" type="int" default="2">
</ApiItem>
<ApiItem kind="constant" name="PADDING_SPACE" type="int" default="6">
</ApiItem>
<ApiItem kind="constant" name="PADDING_ZERO" type="int" default="5">
</ApiItem>

### Properties

<ApiItem kind="property" visibility="protected" name="authData" type="string" default="&quot;&quot;">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="authTag" type="string" default="&quot;&quot;">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="authTagLength" type="int" default="16">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="availableCiphers" type="array" default="[]">
Available cipher methods.
</ApiItem>
<ApiItem kind="property" visibility="protected" name="cipher" type="string" default="self::DEFAULT_CIPHER">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="hashAlgorithm" type="string" default="self::DEFAULT_ALGORITHM">
The name of hashing algorithm.
</ApiItem>
<ApiItem kind="property" visibility="protected" name="hashLengthCache" type="array" default="[]">
Memoized `strlen(hash($algo, "", true))` results, keyed by
algorithm name. The hash output length is deterministic for a
given algorithm, so this collapses the per-decrypt strlen+hash
call to a single hash lookup after warm-up.
</ApiItem>
<ApiItem kind="property" visibility="protected" name="ivLength" type="int" default="16">
The cipher iv length.
</ApiItem>
<ApiItem kind="property" visibility="protected" name="key" type="string" default="&quot;&quot;">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="padFactory" type="PadFactory" default="">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="padding" type="int" default="0">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="useSigning" type="bool" default="true">
Whether calculating message digest enabled or not.
</ApiItem>

### Methods

<h4 id="encryptioncrypt-__construct"><code>__construct()</code></h4>

```php
public function __construct(
string $cipher = self::DEFAULT_CIPHER,
bool $useSigning = true,
PadFactory|null $padFactory = null
);
```

Crypt constructor.

<h4 id="encryptioncrypt-decrypt"><code>decrypt()</code></h4>

```php
public function decrypt(
string $input,
string|null $key = null
): string;
```

Decrypts an encrypted text.

```php
$encrypted = $crypt->decrypt(
$encrypted,
"T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3"
);
```

<h4 id="encryptioncrypt-decryptbase64"><code>decryptBase64()</code></h4>

```php
public function decryptBase64(
string $input,
string|null $key = null,
bool $safe = false
): string;
```

Decrypt a text that is coded as a base64 string.

<h4 id="encryptioncrypt-encrypt"><code>encrypt()</code></h4>

```php
public function encrypt(
string $input,
string|null $key = null
): string;
```

Encrypts a text.

```php
$encrypted = $crypt->encrypt(
"Top secret",
"T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3"
);
```

<h4 id="encryptioncrypt-encryptbase64"><code>encryptBase64()</code></h4>

```php
public function encryptBase64(
string $input,
string|null $key = null,
bool $safe = false
): string;
```

Encrypts a text returning the result as a base64 string.

<h4 id="encryptioncrypt-getauthdata"><code>getAuthData()</code></h4>

```php
public function getAuthData(): string;
```

Returns the auth data

<h4 id="encryptioncrypt-getauthtag"><code>getAuthTag()</code></h4>

```php
public function getAuthTag(): string;
```

Returns the auth tag

<h4 id="encryptioncrypt-getauthtaglength"><code>getAuthTagLength()</code></h4>

```php
public function getAuthTagLength(): int;
```

Returns the auth tag length

<h4 id="encryptioncrypt-getavailableciphers"><code>getAvailableCiphers()</code></h4>

```php
public function getAvailableCiphers(): array;
```

Returns a list of available ciphers.

<h4 id="encryptioncrypt-getavailablehashalgorithms"><code>getAvailableHashAlgorithms()</code></h4>

```php
public function getAvailableHashAlgorithms(): array;
```

Return a list of registered hashing algorithms suitable for hash_hmac.

<h4 id="encryptioncrypt-getcipher"><code>getCipher()</code></h4>

```php
public function getCipher(): string;
```

Returns the current cipher

<h4 id="encryptioncrypt-gethashalgorithm"><code>getHashAlgorithm()</code></h4>

```php
public function getHashAlgorithm(): string;
```

Get the name of hashing algorithm.

<h4 id="encryptioncrypt-getkey"><code>getKey()</code></h4>

```php
public function getKey(): string;
```

Returns the encryption key

<h4 id="encryptioncrypt-isvaliddecryptlength"><code>isValidDecryptLength()</code></h4>

```php
public function isValidDecryptLength( string $input ): bool;
```

Returns if the input length for decryption is valid or not
(number of bytes required by the cipher).

<h4 id="encryptioncrypt-setauthdata"><code>setAuthData()</code></h4>

```php
public function setAuthData( string $data ): CryptInterface;
```

<h4 id="encryptioncrypt-setauthtag"><code>setAuthTag()</code></h4>

```php
public function setAuthTag( string $tag ): CryptInterface;
```

<h4 id="encryptioncrypt-setauthtaglength"><code>setAuthTagLength()</code></h4>

```php
public function setAuthTagLength( int $length ): CryptInterface;
```

<h4 id="encryptioncrypt-setcipher"><code>setCipher()</code></h4>

```php
public function setCipher( string $cipher ): CryptInterface;
```

Sets the cipher algorithm for data encryption and decryption.

<h4 id="encryptioncrypt-sethashalgorithm"><code>setHashAlgorithm()</code></h4>

```php
public function setHashAlgorithm( string $hashAlgorithm ): static;
```

Set the name of hashing algorithm.

<h4 id="encryptioncrypt-setkey"><code>setKey()</code></h4>

```php
public function setKey( string $key ): CryptInterface;
```

Sets the encryption key.

The `$key` should have been previously generated in a cryptographically
safe way.

Bad key:
"le password"

Better (but still unsafe) ->
"#1dj8$=dp?.ak//j1V$~%*0X"

Good key:
"T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3"

<h4 id="encryptioncrypt-setpadding"><code>setPadding()</code></h4>

```php
public function setPadding( int $scheme ): CryptInterface;
```

Changes the padding scheme used.

<h4 id="encryptioncrypt-usesigning"><code>useSigning()</code></h4>

```php
public function useSigning( bool $useSigning ): CryptInterface;
```

Sets if the calculating message digest must used.

<h4 id="encryptioncrypt-checkcipherhashisavailable"><code>checkCipherHashIsAvailable()</code></h4>

```php
protected function checkCipherHashIsAvailable(
string $cipher,
string $type
): void;
```

Checks if a cipher or a hash algorithm is available

<h4 id="encryptioncrypt-cryptpadtext"><code>cryptPadText()</code></h4>

```php
protected function cryptPadText(
string $input,
string $mode,
int $blockSize,
int $paddingType
): string;
```

Pads texts before encryption. See
[cryptopad](https://www.di-mgt.com.au/cryptopad.html)

<h4 id="encryptioncrypt-cryptunpadtext"><code>cryptUnpadText()</code></h4>

```php
protected function cryptUnpadText(
string $input,
string $mode,
int $blockSize,
int $paddingType
): string;
```

Removes a padding from a text.

If the function detects that the text was not padded, it will return it
unmodified.

<h4 id="encryptioncrypt-decryptgcmccmauth"><code>decryptGcmCcmAuth()</code></h4>

```php
protected function decryptGcmCcmAuth(
string $mode,
string $cipherText,
string $decryptKey,
string $iv
): string;
```

<h4 id="encryptioncrypt-decryptgetunpadded"><code>decryptGetUnpadded()</code></h4>

```php
protected function decryptGetUnpadded(
string $mode,
int $blockSize,
string $decrypted
): string;
```

<h4 id="encryptioncrypt-encryptgcmccm"><code>encryptGcmCcm()</code></h4>

```php
protected function encryptGcmCcm(
string $mode,
string $padded,
string $encryptKey,
string $iv
): string;
```

<h4 id="encryptioncrypt-encryptgetpadded"><code>encryptGetPadded()</code></h4>

```php
protected function encryptGetPadded(
string $mode,
string $input,
int $blockSize
): string;
```

<h4 id="encryptioncrypt-initializeavailableciphers"><code>initializeAvailableCiphers()</code></h4>

```php
protected function initializeAvailableCiphers(): static;
```

Initialize available cipher algorithms.

## Encryption\Crypt\CryptInterface

Interface

Interface for Phalcon\Crypt

- [`Phalcon\Contracts\Encryption\Crypt\Crypt`](/5.20/api/phalcon_contracts/#contractsencryptioncryptcrypt)
- **`Phalcon\Encryption\Crypt\CryptInterface`**

`Phalcon\Contracts\Encryption\Crypt\Crypt`

## Encryption\Crypt\Exception\DecryptionFailed

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\DecryptionFailed`**

### Method Summary

<ApiItem href="#encryptioncryptexceptiondecryptionfailed-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptiondecryptionfailed-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\EmptyDecryptionKey

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\EmptyDecryptionKey`**

### Method Summary

<ApiItem href="#encryptioncryptexceptionemptydecryptionkey-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptionemptydecryptionkey-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\EmptyEncryptionKey

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\EmptyEncryptionKey`**

### Method Summary

<ApiItem href="#encryptioncryptexceptionemptyencryptionkey-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptionemptyencryptionkey-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\EncryptionFailed

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\EncryptionFailed`**

### Method Summary

<ApiItem href="#encryptioncryptexceptionencryptionfailed-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptionencryptionfailed-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\Exception

Class

Exceptions thrown in Phalcon\Crypt use this class

- `\Exception`
- **`Phalcon\Encryption\Crypt\Exception\Exception`**
- [`Phalcon\Encryption\Crypt\Exception\DecryptionFailed`](#encryptioncryptexceptiondecryptionfailed)
- [`Phalcon\Encryption\Crypt\Exception\EmptyDecryptionKey`](#encryptioncryptexceptionemptydecryptionkey)
- [`Phalcon\Encryption\Crypt\Exception\EmptyEncryptionKey`](#encryptioncryptexceptionemptyencryptionkey)
- [`Phalcon\Encryption\Crypt\Exception\EncryptionFailed`](#encryptioncryptexceptionencryptionfailed)
- [`Phalcon\Encryption\Crypt\Exception\InvalidAuthTagLength`](#encryptioncryptexceptioninvalidauthtaglength)
- [`Phalcon\Encryption\Crypt\Exception\InvalidDecryptLength`](#encryptioncryptexceptioninvaliddecryptlength)
- [`Phalcon\Encryption\Crypt\Exception\InvalidPaddingSize`](#encryptioncryptexceptioninvalidpaddingsize)
- [`Phalcon\Encryption\Crypt\Exception\IvLengthCalculationFailed`](#encryptioncryptexceptionivlengthcalculationfailed)
- [`Phalcon\Encryption\Crypt\Exception\Mismatch`](#encryptioncryptexceptionmismatch)
- [`Phalcon\Encryption\Crypt\Exception\MissingAuthData`](#encryptioncryptexceptionmissingauthdata)
- [`Phalcon\Encryption\Crypt\Exception\MissingOpensslExtension`](#encryptioncryptexceptionmissingopensslextension)
- [`Phalcon\Encryption\Crypt\Exception\RandomBytesGenerationFailed`](#encryptioncryptexceptionrandombytesgenerationfailed)
- [`Phalcon\Encryption\Crypt\Exception\UnsupportedAlgorithm`](#encryptioncryptexceptionunsupportedalgorithm)

## Encryption\Crypt\Exception\InvalidAuthTagLength

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\InvalidAuthTagLength`**

### Method Summary

<ApiItem href="#encryptioncryptexceptioninvalidauthtaglength-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptioninvalidauthtaglength-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\InvalidDecryptLength

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\InvalidDecryptLength`**

### Method Summary

<ApiItem href="#encryptioncryptexceptioninvaliddecryptlength-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptioninvaliddecryptlength-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\InvalidPaddingSize

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\InvalidPaddingSize`**

### Method Summary

<ApiItem href="#encryptioncryptexceptioninvalidpaddingsize-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptioninvalidpaddingsize-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\IvLengthCalculationFailed

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\IvLengthCalculationFailed`**

### Method Summary

<ApiItem href="#encryptioncryptexceptionivlengthcalculationfailed-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptionivlengthcalculationfailed-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\Mismatch

Class

Exceptions thrown in Phalcon\Crypt will use this class.

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\Mismatch`**

## Encryption\Crypt\Exception\MissingAuthData

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\MissingAuthData`**

### Method Summary

<ApiItem href="#encryptioncryptexceptionmissingauthdata-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptionmissingauthdata-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\MissingOpensslExtension

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\MissingOpensslExtension`**

### Method Summary

<ApiItem href="#encryptioncryptexceptionmissingopensslextension-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptionmissingopensslextension-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\RandomBytesGenerationFailed

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\RandomBytesGenerationFailed`**

### Method Summary

<ApiItem href="#encryptioncryptexceptionrandombytesgenerationfailed-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptionrandombytesgenerationfailed-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Crypt\Exception\UnsupportedAlgorithm

Class

- `\Exception`
- [`Phalcon\Encryption\Crypt\Exception\Exception`](#encryptioncryptexceptionexception)
- **`Phalcon\Encryption\Crypt\Exception\UnsupportedAlgorithm`**

### Method Summary

<ApiItem href="#encryptioncryptexceptionunsupportedalgorithm-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"string","name":"type","default":null},{"type":"string","name":"cipher","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptexceptionunsupportedalgorithm-__construct"><code>__construct()</code></h4>

```php
public function __construct(
string $type,
string $cipher
);
```

## Encryption\Crypt\PadFactory

Class

Factory for creating pad classes

- [`Phalcon\Factory\AbstractConfigFactory`](/5.20/api/phalcon_factory/#factoryabstractconfigfactory)
- [`Phalcon\Factory\AbstractFactory`](/5.20/api/phalcon_factory/#factoryabstractfactory)
- **`Phalcon\Encryption\Crypt\PadFactory`**

`Phalcon\Encryption\Crypt` · `Phalcon\Encryption\Crypt\Exception\Exception` · `Phalcon\Encryption\Crypt\Padding\Ansi` · `Phalcon\Encryption\Crypt\Padding\Iso10126` · `Phalcon\Encryption\Crypt\Padding\IsoIek` · `Phalcon\Encryption\Crypt\Padding\Noop` · `Phalcon\Encryption\Crypt\Padding\PadInterface` · `Phalcon\Encryption\Crypt\Padding\Pkcs7` · `Phalcon\Encryption\Crypt\Padding\Space` · `Phalcon\Encryption\Crypt\Padding\Zero` · `Phalcon\Factory\AbstractFactory`

### Method Summary

<ApiItem href="#encryptioncryptpadfactory-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"array","name":"services","default":"[]"}]}>
AdapterFactory constructor.
</ApiItem>
<ApiItem href="#encryptioncryptpadfactory-newinstance" visibility="public" name="newInstance" returnType="PadInterface" params={[{"type":"string","name":"name","default":null}]}>
Create a new instance of the adapter
</ApiItem>
<ApiItem href="#encryptioncryptpadfactory-padnumbertoservice" visibility="public" name="padNumberToService" returnType="string" params={[{"type":"int","name":"number","default":null}]}>
Gets a Crypt pad constant and returns the unique service name for the
</ApiItem>
<ApiItem href="#encryptioncryptpadfactory-getservices" visibility="protected" name="getServices" returnType="array" params={[]}>
</ApiItem>

### Properties

<ApiItem kind="property" visibility="protected" name="exception" type="string" default="&quot;&quot;">
</ApiItem>

### Methods

<h4 id="encryptioncryptpadfactory-__construct"><code>__construct()</code></h4>

```php
public function __construct( array $services = [] );
```

AdapterFactory constructor.

<h4 id="encryptioncryptpadfactory-newinstance"><code>newInstance()</code></h4>

```php
public function newInstance( string $name ): PadInterface;
```

Create a new instance of the adapter

<h4 id="encryptioncryptpadfactory-padnumbertoservice"><code>padNumberToService()</code></h4>

```php
public function padNumberToService( int $number ): string;
```

Gets a Crypt pad constant and returns the unique service name for the
padding class

<h4 id="encryptioncryptpadfactory-getservices"><code>getServices()</code></h4>

```php
protected function getServices(): array;
```

## Encryption\Crypt\Padding\Ansi

Class

Class Ansi

@package Phalcon\Encryption\Crypt\Padding

- **`Phalcon\Encryption\Crypt\Padding\Ansi`** - implements [`Phalcon\Encryption\Crypt\Padding\PadInterface`](#encryptioncryptpaddingpadinterface)

### Method Summary

<ApiItem href="#encryptioncryptpaddingansi-pad" visibility="public" name="pad" returnType="string" params={[{"type":"int","name":"paddingSize","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncryptpaddingansi-unpad" visibility="public" name="unpad" returnType="int" params={[{"type":"string","name":"input","default":null},{"type":"int","name":"blockSize","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptpaddingansi-pad"><code>pad()</code></h4>

```php
public function pad( int $paddingSize ): string;
```

<h4 id="encryptioncryptpaddingansi-unpad"><code>unpad()</code></h4>

```php
public function unpad(
string $input,
int $blockSize
): int;
```

## Encryption\Crypt\Padding\Iso10126

Class

Class Iso10126

@package Phalcon\Encryption\Crypt\Padding

- **`Phalcon\Encryption\Crypt\Padding\Iso10126`** - implements [`Phalcon\Encryption\Crypt\Padding\PadInterface`](#encryptioncryptpaddingpadinterface)

### Method Summary

<ApiItem href="#encryptioncryptpaddingiso10126-pad" visibility="public" name="pad" returnType="string" params={[{"type":"int","name":"paddingSize","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncryptpaddingiso10126-unpad" visibility="public" name="unpad" returnType="int" params={[{"type":"string","name":"input","default":null},{"type":"int","name":"blockSize","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptpaddingiso10126-pad"><code>pad()</code></h4>

```php
public function pad( int $paddingSize ): string;
```

<h4 id="encryptioncryptpaddingiso10126-unpad"><code>unpad()</code></h4>

```php
public function unpad(
string $input,
int $blockSize
): int;
```

## Encryption\Crypt\Padding\IsoIek

Class

Class IsoIek

@package Phalcon\Encryption\Crypt\Padding

- **`Phalcon\Encryption\Crypt\Padding\IsoIek`** - implements [`Phalcon\Encryption\Crypt\Padding\PadInterface`](#encryptioncryptpaddingpadinterface)

### Method Summary

<ApiItem href="#encryptioncryptpaddingisoiek-pad" visibility="public" name="pad" returnType="string" params={[{"type":"int","name":"paddingSize","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncryptpaddingisoiek-unpad" visibility="public" name="unpad" returnType="int" params={[{"type":"string","name":"input","default":null},{"type":"int","name":"blockSize","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptpaddingisoiek-pad"><code>pad()</code></h4>

```php
public function pad( int $paddingSize ): string;
```

<h4 id="encryptioncryptpaddingisoiek-unpad"><code>unpad()</code></h4>

```php
public function unpad(
string $input,
int $blockSize
): int;
```

## Encryption\Crypt\Padding\Noop

Class

Class Noop

@package Phalcon\Encryption\Crypt\Padding

- **`Phalcon\Encryption\Crypt\Padding\Noop`** - implements [`Phalcon\Encryption\Crypt\Padding\PadInterface`](#encryptioncryptpaddingpadinterface)

### Method Summary

<ApiItem href="#encryptioncryptpaddingnoop-pad" visibility="public" name="pad" returnType="string" params={[{"type":"int","name":"paddingSize","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncryptpaddingnoop-unpad" visibility="public" name="unpad" returnType="int" params={[{"type":"string","name":"input","default":null},{"type":"int","name":"blockSize","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptpaddingnoop-pad"><code>pad()</code></h4>

```php
public function pad( int $paddingSize ): string;
```

<h4 id="encryptioncryptpaddingnoop-unpad"><code>unpad()</code></h4>

```php
public function unpad(
string $input,
int $blockSize
): int;
```

## Encryption\Crypt\Padding\PadInterface

Interface

Interface for Phalcon\Encryption\Crypt\Padding

- [`Phalcon\Contracts\Encryption\Crypt\Padding\Pad`](/5.20/api/phalcon_contracts/#contractsencryptioncryptpaddingpad)
- **`Phalcon\Encryption\Crypt\Padding\PadInterface`**

`Phalcon\Contracts\Encryption\Crypt\Padding\Pad`

## Encryption\Crypt\Padding\Pkcs7

Class

Class Pkcs7

@package Phalcon\Encryption\Crypt\Padding

- **`Phalcon\Encryption\Crypt\Padding\Pkcs7`** - implements [`Phalcon\Encryption\Crypt\Padding\PadInterface`](#encryptioncryptpaddingpadinterface)

### Method Summary

<ApiItem href="#encryptioncryptpaddingpkcs7-pad" visibility="public" name="pad" returnType="string" params={[{"type":"int","name":"paddingSize","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncryptpaddingpkcs7-unpad" visibility="public" name="unpad" returnType="int" params={[{"type":"string","name":"input","default":null},{"type":"int","name":"blockSize","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptpaddingpkcs7-pad"><code>pad()</code></h4>

```php
public function pad( int $paddingSize ): string;
```

<h4 id="encryptioncryptpaddingpkcs7-unpad"><code>unpad()</code></h4>

```php
public function unpad(
string $input,
int $blockSize
): int;
```

## Encryption\Crypt\Padding\Space

Class

Class Space

@package Phalcon\Encryption\Crypt\Padding

- **`Phalcon\Encryption\Crypt\Padding\Space`** - implements [`Phalcon\Encryption\Crypt\Padding\PadInterface`](#encryptioncryptpaddingpadinterface)

### Method Summary

<ApiItem href="#encryptioncryptpaddingspace-pad" visibility="public" name="pad" returnType="string" params={[{"type":"int","name":"paddingSize","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncryptpaddingspace-unpad" visibility="public" name="unpad" returnType="int" params={[{"type":"string","name":"input","default":null},{"type":"int","name":"blockSize","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptpaddingspace-pad"><code>pad()</code></h4>

```php
public function pad( int $paddingSize ): string;
```

<h4 id="encryptioncryptpaddingspace-unpad"><code>unpad()</code></h4>

```php
public function unpad(
string $input,
int $blockSize
): int;
```

## Encryption\Crypt\Padding\Zero

Class

Class Zero

@package Phalcon\Encryption\Crypt\Padding

- **`Phalcon\Encryption\Crypt\Padding\Zero`** - implements [`Phalcon\Encryption\Crypt\Padding\PadInterface`](#encryptioncryptpaddingpadinterface)

### Method Summary

<ApiItem href="#encryptioncryptpaddingzero-pad" visibility="public" name="pad" returnType="string" params={[{"type":"int","name":"paddingSize","default":null}]}>
</ApiItem>
<ApiItem href="#encryptioncryptpaddingzero-unpad" visibility="public" name="unpad" returnType="int" params={[{"type":"string","name":"input","default":null},{"type":"int","name":"blockSize","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptioncryptpaddingzero-pad"><code>pad()</code></h4>

```php
public function pad( int $paddingSize ): string;
```

<h4 id="encryptioncryptpaddingzero-unpad"><code>unpad()</code></h4>

```php
public function unpad(
string $input,
int $blockSize
): int;
```

## Encryption\Security

Class

This component provides a set of functions to improve the security in Phalcon
applications

```php
$login    = $this->request->getPost("login");
$password = $this->request->getPost("password");

$user = Users::findFirstByLogin($login);

if ($user) {
if ($this->security->checkHash($password, $user->password)) {
    // The password is valid
}
}
```

- `\stdClass`
- [`Phalcon\Di\AbstractInjectionAware`](/5.20/api/phalcon_di/#diabstractinjectionaware)
- **`Phalcon\Encryption\Security`** - implements [`Phalcon\Contracts\Encryption\Security\Security`](/5.20/api/phalcon_contracts/#contractsencryptionsecuritysecurity)

`Phalcon\Contracts\Encryption\Security\Security` · `Phalcon\Di\AbstractInjectionAware` · `Phalcon\Di\DiInterface` · `Phalcon\Encryption\Security\Exception` · `Phalcon\Encryption\Security\Exceptions\UnknownHashAlgorithm` · `Phalcon\Encryption\Security\Random` · `Phalcon\Http\RequestInterface` · `Phalcon\Session\ManagerInterface` · `Phalcon\Traits\Php\HashTrait`

### Method Summary

<ApiItem href="#encryptionsecurity-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"SessionInterface|null","name":"session","default":"null"},{"type":"RequestInterface|null","name":"request","default":"null"}]}>
Security constructor.
</ApiItem>
<ApiItem href="#encryptionsecurity-checkhash" visibility="public" name="checkHash" returnType="bool" params={[{"type":"string","name":"password","default":null},{"type":"string","name":"passwordHash","default":null},{"type":"int","name":"maxPassLength","default":"0"}]}>
Checks a plain text password and its hash version to check if the
</ApiItem>
<ApiItem href="#encryptionsecurity-checktoken" visibility="public" name="checkToken" returnType="bool" params={[{"type":"string|null","name":"tokenKey","default":"null"},{"type":"mixed","name":"tokenValue","default":"null"},{"type":"bool","name":"destroyIfValid","default":"true"}]}>
Check if the CSRF token sent in the request is the same that the current
</ApiItem>
<ApiItem href="#encryptionsecurity-computehmac" visibility="public" name="computeHmac" returnType="string" params={[{"type":"string","name":"data","default":null},{"type":"string","name":"key","default":null},{"type":"string","name":"algorithm","default":null},{"type":"bool","name":"raw","default":"false"}]}>
Computes a HMAC
</ApiItem>
<ApiItem href="#encryptionsecurity-destroytoken" visibility="public" name="destroyToken" returnType="static" params={[]}>
Removes the value of the CSRF token and key from session
</ApiItem>
<ApiItem href="#encryptionsecurity-getdefaulthash" visibility="public" name="getDefaultHash" returnType="int" params={[]}>
Returns the default hash
</ApiItem>
<ApiItem href="#encryptionsecurity-gethashinformation" visibility="public" name="getHashInformation" returnType="array" params={[{"type":"string","name":"hash","default":null}]}>
Returns information regarding a hash
</ApiItem>
<ApiItem href="#encryptionsecurity-getrandom" visibility="public" name="getRandom" returnType="Random" params={[]}>
Returns a secure random number generator instance
</ApiItem>
<ApiItem href="#encryptionsecurity-getrandombytes" visibility="public" name="getRandomBytes" returnType="int" params={[]}>
Returns a number of bytes to be generated by the openssl pseudo random
</ApiItem>
<ApiItem href="#encryptionsecurity-getrequesttoken" visibility="public" name="getRequestToken" returnType="string|null" params={[]}>
Returns the value of the CSRF token for the current request.
</ApiItem>
<ApiItem href="#encryptionsecurity-getsaltbytes" visibility="public" name="getSaltBytes" returnType="string" params={[{"type":"int","name":"numberBytes","default":"0"}]}>
Generate a >22-length pseudo random string to be used as salt for
</ApiItem>
<ApiItem href="#encryptionsecurity-getsessiontoken" visibility="public" name="getSessionToken" returnType="string|null" params={[]}>
Returns the value of the CSRF token in session
</ApiItem>
<ApiItem href="#encryptionsecurity-gettoken" visibility="public" name="getToken" returnType="string|null" params={[]}>
Generates a pseudo random token value to be used as input's value in a
</ApiItem>
<ApiItem href="#encryptionsecurity-gettokenkey" visibility="public" name="getTokenKey" returnType="string|null" params={[]}>
Generates a pseudo random token key to be used as input's name in a CSRF
</ApiItem>
<ApiItem href="#encryptionsecurity-getworkfactor" visibility="public" name="getWorkFactor" returnType="int" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurity-hash" visibility="public" name="hash" returnType="string" params={[{"type":"string","name":"password","default":null},{"type":"array","name":"options","default":"[]"}]}>
Creates a password hash using bcrypt with a pseudo random salt
</ApiItem>
<ApiItem href="#encryptionsecurity-islegacyhash" visibility="public" name="isLegacyHash" returnType="bool" params={[{"type":"string","name":"passwordHash","default":null}]}>
Checks if a password hash is a valid bcrypt's hash
</ApiItem>
<ApiItem href="#encryptionsecurity-refreshtoken" visibility="public" name="refreshToken" returnType="static" params={[]}>
Forces the regeneration of the CSRF token and key, writing the new
</ApiItem>
<ApiItem href="#encryptionsecurity-setautorefresh" visibility="public" name="setAutoRefresh" returnType="static" params={[{"type":"bool","name":"autoRefresh","default":null}]}>
Toggles automatic regeneration of the CSRF token on every call to
</ApiItem>
<ApiItem href="#encryptionsecurity-setdefaulthash" visibility="public" name="setDefaultHash" returnType="static" params={[{"type":"int","name":"defaultHash","default":null}]}>
Sets the default hash
</ApiItem>
<ApiItem href="#encryptionsecurity-setrandombytes" visibility="public" name="setRandomBytes" returnType="static" params={[{"type":"int","name":"randomBytes","default":null}]}>
Sets a number of bytes to be generated by the openssl pseudo random
</ApiItem>
<ApiItem href="#encryptionsecurity-setworkfactor" visibility="public" name="setWorkFactor" returnType="static" params={[{"type":"int","name":"workFactor","default":null}]}>
Sets the work factor
</ApiItem>
<ApiItem href="#encryptionsecurity-getlocalservice" visibility="protected" name="getLocalService" returnType="" params={[{"type":"string","name":"name","default":null},{"type":"string","name":"property","default":null}]}>
</ApiItem>

### Constants

<ApiItem kind="constant" name="CRYPT_ARGON2I" type="int" default="10">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_ARGON2ID" type="int" default="11">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_BCRYPT" type="int" default="0">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_BLOWFISH" type="int" default="4">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_BLOWFISH_A" type="int" default="5">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_BLOWFISH_X" type="int" default="6">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_BLOWFISH_Y" type="int" default="7">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_DEFAULT" type="int" default="0">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_EXT_DES" type="int" default="2">
</ApiItem>
<ApiItem kind="constant" name="CRYPT_MD5" type="int" default="3">
Weak legacy algorithm, easier to brute-force than bcrypt or Argon2. Use
`CRYPT_DEFAULT` (bcrypt) or the Argon2 algorithms and rehash stored
passwords on login. To be removed in a future major version.
</ApiItem>
<ApiItem kind="constant" name="CRYPT_SHA256" type="int" default="8">
Weak legacy algorithm, easier to brute-force than bcrypt or Argon2. Use
`CRYPT_DEFAULT` (bcrypt) or the Argon2 algorithms and rehash stored
passwords on login. To be removed in a future major version.
</ApiItem>
<ApiItem kind="constant" name="CRYPT_SHA512" type="int" default="9">
Weak legacy algorithm, easier to brute-force than bcrypt or Argon2. Use
`CRYPT_DEFAULT` (bcrypt) or the Argon2 algorithms and rehash stored
passwords on login. To be removed in a future major version.
</ApiItem>
<ApiItem kind="constant" name="CRYPT_STD_DES" type="int" default="1">
</ApiItem>

### Properties

<ApiItem kind="property" visibility="protected" name="autoRefresh" type="bool" default="true">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="defaultHash" type="int" default="self::CRYPT_DEFAULT">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="numberBytes" type="int" default="16">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="random" type="Random" default="">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="requestToken" type="string|null" default="null">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="token" type="string|null" default="null">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="tokenKey" type="string|null" default="null">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="tokenKeySessionId" type="string" default="&quot;$PHALCON/CSRF/KEY$&quot;">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="tokenValueSessionId" type="string" default="&quot;$PHALCON/CSRF$&quot;">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="workFactor" type="int" default="10">
</ApiItem>

### Methods

<h4 id="encryptionsecurity-__construct"><code>__construct()</code></h4>

```php
public function __construct(
SessionInterface|null $session = null,
RequestInterface|null $request = null
);
```

Security constructor.

<h4 id="encryptionsecurity-checkhash"><code>checkHash()</code></h4>

```php
public function checkHash(
string $password,
string $passwordHash,
int $maxPassLength = 0
): bool;
```

Checks a plain text password and its hash version to check if the
password matches

<h4 id="encryptionsecurity-checktoken"><code>checkToken()</code></h4>

```php
public function checkToken(
string|null $tokenKey = null,
mixed $tokenValue = null,
bool $destroyIfValid = true
): bool;
```

Check if the CSRF token sent in the request is the same that the current
in session

<h4 id="encryptionsecurity-computehmac"><code>computeHmac()</code></h4>

```php
public function computeHmac(
string $data,
string $key,
string $algorithm,
bool $raw = false
): string;
```

Computes a HMAC

<h4 id="encryptionsecurity-destroytoken"><code>destroyToken()</code></h4>

```php
public function destroyToken(): static;
```

Removes the value of the CSRF token and key from session

<h4 id="encryptionsecurity-getdefaulthash"><code>getDefaultHash()</code></h4>

```php
public function getDefaultHash(): int;
```

Returns the default hash

<h4 id="encryptionsecurity-gethashinformation"><code>getHashInformation()</code></h4>

```php
public function getHashInformation( string $hash ): array;
```

Returns information regarding a hash

<h4 id="encryptionsecurity-getrandom"><code>getRandom()</code></h4>

```php
public function getRandom(): Random;
```

Returns a secure random number generator instance

<h4 id="encryptionsecurity-getrandombytes"><code>getRandomBytes()</code></h4>

```php
public function getRandomBytes(): int;
```

Returns a number of bytes to be generated by the openssl pseudo random
generator

<h4 id="encryptionsecurity-getrequesttoken"><code>getRequestToken()</code></h4>

```php
public function getRequestToken(): string|null;
```

Returns the value of the CSRF token for the current request.

<h4 id="encryptionsecurity-getsaltbytes"><code>getSaltBytes()</code></h4>

```php
public function getSaltBytes( int $numberBytes = 0 ): string;
```

Generate a >22-length pseudo random string to be used as salt for
passwords

<h4 id="encryptionsecurity-getsessiontoken"><code>getSessionToken()</code></h4>

```php
public function getSessionToken(): string|null;
```

Returns the value of the CSRF token in session

<h4 id="encryptionsecurity-gettoken"><code>getToken()</code></h4>

```php
public function getToken(): string|null;
```

Generates a pseudo random token value to be used as input's value in a
CSRF check

<h4 id="encryptionsecurity-gettokenkey"><code>getTokenKey()</code></h4>

```php
public function getTokenKey(): string|null;
```

Generates a pseudo random token key to be used as input's name in a CSRF
check

<h4 id="encryptionsecurity-getworkfactor"><code>getWorkFactor()</code></h4>

```php
public function getWorkFactor(): int;
```

<h4 id="encryptionsecurity-hash"><code>hash()</code></h4>

```php
public function hash(
string $password,
array $options = []
): string;
```

Creates a password hash using bcrypt with a pseudo random salt

Any `defaultHash` value that is not explicitly handled (including the
deprecated, unimplemented constants) resolves to bcrypt.

<h4 id="encryptionsecurity-islegacyhash"><code>isLegacyHash()</code></h4>

```php
public function isLegacyHash( string $passwordHash ): bool;
```

Checks if a password hash is a valid bcrypt's hash

<h4 id="encryptionsecurity-refreshtoken"><code>refreshToken()</code></h4>

```php
public function refreshToken(): static;
```

Forces the regeneration of the CSRF token and key, writing the new
values to the session even when auto-refresh has been disabled. Useful
after a successful login or any other state change where rotating the
token is appropriate.

<h4 id="encryptionsecurity-setautorefresh"><code>setAutoRefresh()</code></h4>

```php
public function setAutoRefresh( bool $autoRefresh ): static;
```

Toggles automatic regeneration of the CSRF token on every call to
`getToken()` / `getTokenKey()`. When set to `false`, existing session
values are reused (no session write), and a new token is only minted
when none is present or `refreshToken()` is called explicitly.

<h4 id="encryptionsecurity-setdefaulthash"><code>setDefaultHash()</code></h4>

```php
public function setDefaultHash( int $defaultHash ): static;
```

Sets the default hash

<h4 id="encryptionsecurity-setrandombytes"><code>setRandomBytes()</code></h4>

```php
public function setRandomBytes( int $randomBytes ): static;
```

Sets a number of bytes to be generated by the openssl pseudo random
generator

<h4 id="encryptionsecurity-setworkfactor"><code>setWorkFactor()</code></h4>

```php
public function setWorkFactor( int $workFactor ): static;
```

Sets the work factor

<h4 id="encryptionsecurity-getlocalservice"><code>getLocalService()</code></h4>

```php
protected function getLocalService(
string $name,
string $property
);
```

## Encryption\Security\Exception

Class

Phalcon\Encryption\Security\Exception

Exceptions thrown in Phalcon\Security will use this class

- `\Exception`
- **`Phalcon\Encryption\Security\Exception`**
- [`Phalcon\Encryption\Security\Exceptions\InvalidRandomInput`](#encryptionsecurityexceptionsinvalidrandominput)
- [`Phalcon\Encryption\Security\Exceptions\UnknownHashAlgorithm`](#encryptionsecurityexceptionsunknownhashalgorithm)

## Encryption\Security\Exceptions\InvalidRandomInput

Class

- `\Exception`
- [`Phalcon\Encryption\Security\Exception`](#encryptionsecurityexception)
- **`Phalcon\Encryption\Security\Exceptions\InvalidRandomInput`**

`Phalcon\Encryption\Security\Exception`

### Method Summary

<ApiItem href="#encryptionsecurityexceptionsinvalidrandominput-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityexceptionsinvalidrandominput-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\Exceptions\UnknownHashAlgorithm

Class

- `\Exception`
- [`Phalcon\Encryption\Security\Exception`](#encryptionsecurityexception)
- **`Phalcon\Encryption\Security\Exceptions\UnknownHashAlgorithm`**

`Phalcon\Encryption\Security\Exception`

### Method Summary

<ApiItem href="#encryptionsecurityexceptionsunknownhashalgorithm-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"string","name":"algo","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityexceptionsunknownhashalgorithm-__construct"><code>__construct()</code></h4>

```php
public function __construct( string $algo );
```

## Encryption\Security\JWT\Builder

Class

JWT Builder

@link https://tools.ietf.org/html/rfc7519

- **`Phalcon\Encryption\Security\JWT\Builder`**

`Phalcon\Encryption\Security\JWT\Exceptions\EmptyPassphrase` · `Phalcon\Encryption\Security\JWT\Exceptions\InvalidAudience` · `Phalcon\Encryption\Security\JWT\Exceptions\InvalidExpirationTime` · `Phalcon\Encryption\Security\JWT\Exceptions\InvalidNotBefore` · `Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException` · `Phalcon\Encryption\Security\JWT\Exceptions\WeakPassphrase` · `Phalcon\Encryption\Security\JWT\Signer\SignerInterface` · `Phalcon\Encryption\Security\JWT\Token\Enum` · `Phalcon\Encryption\Security\JWT\Token\Item` · `Phalcon\Encryption\Security\JWT\Token\Signature` · `Phalcon\Encryption\Security\JWT\Token\Token` · `Phalcon\Support\Collection` · `Phalcon\Support\Collection\CollectionInterface` · `Phalcon\Support\Helper\Json\Encode` · `Phalcon\Traits\Php\Base64Trait`

### Method Summary

<ApiItem href="#encryptionsecurityjwtbuilder-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"SignerInterface","name":"signer","default":null}]}>
Builder constructor.
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-addclaim" visibility="public" name="addClaim" returnType="static" params={[{"type":"string","name":"name","default":null},{"type":"mixed","name":"value","default":null}]}>
Adds a custom claim
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-addheader" visibility="public" name="addHeader" returnType="static" params={[{"type":"string","name":"name","default":null},{"type":"mixed","name":"value","default":null}]}>
Adds a custom claim
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getaudience" visibility="public" name="getAudience" returnType="" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getclaims" visibility="public" name="getClaims" returnType="array" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getcontenttype" visibility="public" name="getContentType" returnType="string|null" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getexpirationtime" visibility="public" name="getExpirationTime" returnType="int|null" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getheaders" visibility="public" name="getHeaders" returnType="array" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getid" visibility="public" name="getId" returnType="string|null" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getissuedat" visibility="public" name="getIssuedAt" returnType="int|null" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getissuer" visibility="public" name="getIssuer" returnType="string|null" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getnotbefore" visibility="public" name="getNotBefore" returnType="int|null" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getpassphrase" visibility="public" name="getPassphrase" returnType="string" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-getsubject" visibility="public" name="getSubject" returnType="string|null" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-gettoken" visibility="public" name="getToken" returnType="Token" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-init" visibility="public" name="init" returnType="static" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setaudience" visibility="public" name="setAudience" returnType="static" params={[{"type":"mixed","name":"audience","default":null}]}>
The "aud" (audience) claim identifies the recipients that the JWT is
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setcontenttype" visibility="public" name="setContentType" returnType="static" params={[{"type":"string","name":"contentType","default":null}]}>
Sets the content type header 'cty'
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setexpirationtime" visibility="public" name="setExpirationTime" returnType="static" params={[{"type":"int","name":"timestamp","default":null}]}>
The "exp" (expiration time) claim identifies the expiration time on
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setid" visibility="public" name="setId" returnType="static" params={[{"type":"string","name":"jwtId","default":null}]}>
The "jti" (JWT ID) claim provides a unique identifier for the JWT.
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setissuedat" visibility="public" name="setIssuedAt" returnType="static" params={[{"type":"int","name":"timestamp","default":null}]}>
The "iat" (issued at) claim identifies the time at which the JWT was
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setissuer" visibility="public" name="setIssuer" returnType="static" params={[{"type":"string","name":"issuer","default":null}]}>
The "iss" (issuer) claim identifies the principal that issued the
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setnotbefore" visibility="public" name="setNotBefore" returnType="static" params={[{"type":"int","name":"timestamp","default":null}]}>
The "nbf" (not before) claim identifies the time before which the JWT
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setpassphrase" visibility="public" name="setPassphrase" returnType="static" params={[{"type":"string","name":"passphrase","default":null}]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setsubject" visibility="public" name="setSubject" returnType="static" params={[{"type":"string","name":"subject","default":null}]}>
The "sub" (subject) claim identifies the principal that is the
</ApiItem>
<ApiItem href="#encryptionsecurityjwtbuilder-setclaim" visibility="protected" name="setClaim" returnType="Builder" params={[{"type":"string","name":"name","default":null},{"type":"mixed","name":"value","default":null}]}>
Sets a registered claim
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtbuilder-__construct"><code>__construct()</code></h4>

```php
public function __construct( SignerInterface $signer );
```

Builder constructor.

<h4 id="encryptionsecurityjwtbuilder-addclaim"><code>addClaim()</code></h4>

```php
public function addClaim(
string $name,
mixed $value
): static;
```

Adds a custom claim

<h4 id="encryptionsecurityjwtbuilder-addheader"><code>addHeader()</code></h4>

```php
public function addHeader(
string $name,
mixed $value
): static;
```

Adds a custom claim

<h4 id="encryptionsecurityjwtbuilder-getaudience"><code>getAudience()</code></h4>

```php
public function getAudience();
```

<h4 id="encryptionsecurityjwtbuilder-getclaims"><code>getClaims()</code></h4>

```php
public function getClaims(): array;
```

<h4 id="encryptionsecurityjwtbuilder-getcontenttype"><code>getContentType()</code></h4>

```php
public function getContentType(): string|null;
```

<h4 id="encryptionsecurityjwtbuilder-getexpirationtime"><code>getExpirationTime()</code></h4>

```php
public function getExpirationTime(): int|null;
```

<h4 id="encryptionsecurityjwtbuilder-getheaders"><code>getHeaders()</code></h4>

```php
public function getHeaders(): array;
```

<h4 id="encryptionsecurityjwtbuilder-getid"><code>getId()</code></h4>

```php
public function getId(): string|null;
```

<h4 id="encryptionsecurityjwtbuilder-getissuedat"><code>getIssuedAt()</code></h4>

```php
public function getIssuedAt(): int|null;
```

<h4 id="encryptionsecurityjwtbuilder-getissuer"><code>getIssuer()</code></h4>

```php
public function getIssuer(): string|null;
```

<h4 id="encryptionsecurityjwtbuilder-getnotbefore"><code>getNotBefore()</code></h4>

```php
public function getNotBefore(): int|null;
```

<h4 id="encryptionsecurityjwtbuilder-getpassphrase"><code>getPassphrase()</code></h4>

```php
public function getPassphrase(): string;
```

<h4 id="encryptionsecurityjwtbuilder-getsubject"><code>getSubject()</code></h4>

```php
public function getSubject(): string|null;
```

<h4 id="encryptionsecurityjwtbuilder-gettoken"><code>getToken()</code></h4>

```php
public function getToken(): Token;
```

<h4 id="encryptionsecurityjwtbuilder-init"><code>init()</code></h4>

```php
public function init(): static;
```

<h4 id="encryptionsecurityjwtbuilder-setaudience"><code>setAudience()</code></h4>

```php
public function setAudience( mixed $audience ): static;
```

The "aud" (audience) claim identifies the recipients that the JWT is
intended for.  Each principal intended to process the JWT MUST
identify itself with a value in the audience claim.  If the principal
processing the claim does not identify itself with a value in the
"aud" claim when this claim is present, then the JWT MUST be
rejected.  In the general case, the "aud" value is an array of case-
sensitive strings, each containing a StringOrURI value.  In the
special case when the JWT has one audience, the "aud" value MAY be a
single case-sensitive string containing a StringOrURI value.  The
interpretation of audience values is generally application specific.
Use of this claim is OPTIONAL.

<h4 id="encryptionsecurityjwtbuilder-setcontenttype"><code>setContentType()</code></h4>

```php
public function setContentType( string $contentType ): static;
```

Sets the content type header 'cty'

<h4 id="encryptionsecurityjwtbuilder-setexpirationtime"><code>setExpirationTime()</code></h4>

```php
public function setExpirationTime( int $timestamp ): static;
```

The "exp" (expiration time) claim identifies the expiration time on
or after which the JWT MUST NOT be accepted for processing.  The
processing of the "exp" claim requires that the current date/time
MUST be before the expiration date/time listed in the "exp" claim.
Implementers MAY provide for some small leeway, usually no more than
a few minutes, to account for clock skew.  Its value MUST be a number
containing a NumericDate value.  Use of this claim is OPTIONAL.

<h4 id="encryptionsecurityjwtbuilder-setid"><code>setId()</code></h4>

```php
public function setId( string $jwtId ): static;
```

The "jti" (JWT ID) claim provides a unique identifier for the JWT.
The identifier value MUST be assigned in a manner that ensures that
there is a negligible probability that the same value will be
accidentally assigned to a different data object; if the application
uses multiple issuers, collisions MUST be prevented among values
produced by different issuers as well.  The "jti" claim can be used
to prevent the JWT from being replayed.  The "jti" value is a case-
sensitive string.  Use of this claim is OPTIONAL.

<h4 id="encryptionsecurityjwtbuilder-setissuedat"><code>setIssuedAt()</code></h4>

```php
public function setIssuedAt( int $timestamp ): static;
```

The "iat" (issued at) claim identifies the time at which the JWT was
issued.  This claim can be used to determine the age of the JWT.  Its
value MUST be a number containing a NumericDate value.  Use of this
claim is OPTIONAL.

<h4 id="encryptionsecurityjwtbuilder-setissuer"><code>setIssuer()</code></h4>

```php
public function setIssuer( string $issuer ): static;
```

The "iss" (issuer) claim identifies the principal that issued the
JWT.  The processing of this claim is generally application specific.
The "iss" value is a case-sensitive string containing a StringOrURI
value.  Use of this claim is OPTIONAL.

<h4 id="encryptionsecurityjwtbuilder-setnotbefore"><code>setNotBefore()</code></h4>

```php
public function setNotBefore( int $timestamp ): static;
```

The "nbf" (not before) claim identifies the time before which the JWT
MUST NOT be accepted for processing.  The processing of the "nbf"
claim requires that the current date/time MUST be after or equal to
the not-before date/time listed in the "nbf" claim.  Implementers MAY
provide for some small leeway, usually no more than a few minutes, to
account for clock skew.  Its value MUST be a number containing a
NumericDate value.  Use of this claim is OPTIONAL.

<h4 id="encryptionsecurityjwtbuilder-setpassphrase"><code>setPassphrase()</code></h4>

```php
public function setPassphrase( string $passphrase ): static;
```

<h4 id="encryptionsecurityjwtbuilder-setsubject"><code>setSubject()</code></h4>

```php
public function setSubject( string $subject ): static;
```

The "sub" (subject) claim identifies the principal that is the
subject of the JWT.  The claims in a JWT are normally statements
about the subject.  The subject value MUST either be scoped to be
locally unique in the context of the issuer or be globally unique.
The processing of this claim is generally application specific.  The
"sub" value is a case-sensitive string containing a StringOrURI
value.  Use of this claim is OPTIONAL.

<h4 id="encryptionsecurityjwtbuilder-setclaim"><code>setClaim()</code></h4>

```php
protected function setClaim(
string $name,
mixed $value
): Builder;
```

Sets a registered claim

## Encryption\Security\JWT\Exceptions\EmptyPassphrase

Class

- `\Exception`
- [`Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException`](#encryptionsecurityjwtexceptionsvalidatorexception)
- **`Phalcon\Encryption\Security\JWT\Exceptions\EmptyPassphrase`**

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsemptypassphrase-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsemptypassphrase-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\InvalidAudience

Class

- `\Exception`
- [`Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException`](#encryptionsecurityjwtexceptionsvalidatorexception)
- **`Phalcon\Encryption\Security\JWT\Exceptions\InvalidAudience`**

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsinvalidaudience-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsinvalidaudience-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\InvalidAudienceType

Class

- `\Exception`
- [`Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException`](#encryptionsecurityjwtexceptionsvalidatorexception)
- **`Phalcon\Encryption\Security\JWT\Exceptions\InvalidAudienceType`**

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsinvalidaudiencetype-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsinvalidaudiencetype-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\InvalidClaims

Class

- `\InvalidArgumentException`
- **`Phalcon\Encryption\Security\JWT\Exceptions\InvalidClaims`**

`InvalidArgumentException`

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsinvalidclaims-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsinvalidclaims-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\InvalidExpirationTime

Class

- `\Exception`
- [`Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException`](#encryptionsecurityjwtexceptionsvalidatorexception)
- **`Phalcon\Encryption\Security\JWT\Exceptions\InvalidExpirationTime`**

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsinvalidexpirationtime-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsinvalidexpirationtime-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\InvalidHeader

Class

- `\InvalidArgumentException`
- **`Phalcon\Encryption\Security\JWT\Exceptions\InvalidHeader`**

`InvalidArgumentException`

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsinvalidheader-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsinvalidheader-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\InvalidNotBefore

Class

- `\Exception`
- [`Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException`](#encryptionsecurityjwtexceptionsvalidatorexception)
- **`Phalcon\Encryption\Security\JWT\Exceptions\InvalidNotBefore`**

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsinvalidnotbefore-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsinvalidnotbefore-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\MalformedJwtString

Class

- `\InvalidArgumentException`
- **`Phalcon\Encryption\Security\JWT\Exceptions\MalformedJwtString`**

`InvalidArgumentException`

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsmalformedjwtstring-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsmalformedjwtstring-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\MissingJwtTypHeader

Class

- `\InvalidArgumentException`
- **`Phalcon\Encryption\Security\JWT\Exceptions\MissingJwtTypHeader`**

`InvalidArgumentException`

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsmissingjwttypheader-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsmissingjwttypheader-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\UnsupportedAlgorithmException

Class

Exception thrown when the algorithm is not supported for JWT

- `\Exception`
- **`Phalcon\Encryption\Security\JWT\Exceptions\UnsupportedAlgorithmException`**
- [`Phalcon\Encryption\Security\JWT\Exceptions\UnsupportedHmacAlgorithm`](#encryptionsecurityjwtexceptionsunsupportedhmacalgorithm)

`Exception`

## Encryption\Security\JWT\Exceptions\UnsupportedHmacAlgorithm

Class

- `\Exception`
- [`Phalcon\Encryption\Security\JWT\Exceptions\UnsupportedAlgorithmException`](#encryptionsecurityjwtexceptionsunsupportedalgorithmexception)
- **`Phalcon\Encryption\Security\JWT\Exceptions\UnsupportedHmacAlgorithm`**

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsunsupportedhmacalgorithm-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsunsupportedhmacalgorithm-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Exceptions\ValidatorException

Class

Exception thrown when the validation does not pass for JWT

- `\Exception`
- **`Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException`**
- [`Phalcon\Encryption\Security\JWT\Exceptions\EmptyPassphrase`](#encryptionsecurityjwtexceptionsemptypassphrase)
- [`Phalcon\Encryption\Security\JWT\Exceptions\InvalidAudience`](#encryptionsecurityjwtexceptionsinvalidaudience)
- [`Phalcon\Encryption\Security\JWT\Exceptions\InvalidAudienceType`](#encryptionsecurityjwtexceptionsinvalidaudiencetype)
- [`Phalcon\Encryption\Security\JWT\Exceptions\InvalidExpirationTime`](#encryptionsecurityjwtexceptionsinvalidexpirationtime)
- [`Phalcon\Encryption\Security\JWT\Exceptions\InvalidNotBefore`](#encryptionsecurityjwtexceptionsinvalidnotbefore)
- [`Phalcon\Encryption\Security\JWT\Exceptions\WeakPassphrase`](#encryptionsecurityjwtexceptionsweakpassphrase)

`Exception`

## Encryption\Security\JWT\Exceptions\WeakPassphrase

Class

- `\Exception`
- [`Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException`](#encryptionsecurityjwtexceptionsvalidatorexception)
- **`Phalcon\Encryption\Security\JWT\Exceptions\WeakPassphrase`**

### Method Summary

<ApiItem href="#encryptionsecurityjwtexceptionsweakpassphrase-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtexceptionsweakpassphrase-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\JWT\Signer\AbstractSigner

Abstract

Abstract class helping with the signer classes

- **`Phalcon\Encryption\Security\JWT\Signer\AbstractSigner`** - implements [`Phalcon\Encryption\Security\JWT\Signer\SignerInterface`](#encryptionsecurityjwtsignersignerinterface)
- [`Phalcon\Encryption\Security\JWT\Signer\Hmac`](#encryptionsecurityjwtsignerhmac)

### Method Summary

<ApiItem href="#encryptionsecurityjwtsignerabstractsigner-getalgorithm" visibility="public" name="getAlgorithm" returnType="string" params={[]}>
</ApiItem>

### Properties

<ApiItem kind="property" visibility="protected" name="algorithm" type="string" default="&quot;&quot;">
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtsignerabstractsigner-getalgorithm"><code>getAlgorithm()</code></h4>

```php
public function getAlgorithm(): string;
```

## Encryption\Security\JWT\Signer\Hmac

Class

HMAC signing class

- [`Phalcon\Encryption\Security\JWT\Signer\AbstractSigner`](#encryptionsecurityjwtsignerabstractsigner)
- **`Phalcon\Encryption\Security\JWT\Signer\Hmac`**

`Phalcon\Encryption\Security\JWT\Exceptions\UnsupportedAlgorithmException` · `Phalcon\Encryption\Security\JWT\Exceptions\UnsupportedHmacAlgorithm` · `Phalcon\Traits\Php\HashTrait`

### Method Summary

<ApiItem href="#encryptionsecurityjwtsignerhmac-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"string","name":"algo","default":"\"sha512\""}]}>
Hmac constructor.
</ApiItem>
<ApiItem href="#encryptionsecurityjwtsignerhmac-getalgheader" visibility="public" name="getAlgHeader" returnType="string" params={[]}>
Return the value that is used for the "alg" header
</ApiItem>
<ApiItem href="#encryptionsecurityjwtsignerhmac-sign" visibility="public" name="sign" returnType="string" params={[{"type":"string","name":"payload","default":null},{"type":"string","name":"passphrase","default":null}]}>
Sign a payload using the passphrase
</ApiItem>
<ApiItem href="#encryptionsecurityjwtsignerhmac-verify" visibility="public" name="verify" returnType="bool" params={[{"type":"string","name":"source","default":null},{"type":"string","name":"payload","default":null},{"type":"string","name":"passphrase","default":null}]}>
Verify a passed source with a payload and passphrase
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtsignerhmac-__construct"><code>__construct()</code></h4>

```php
public function __construct( string $algo = "sha512" );
```

Hmac constructor.

<h4 id="encryptionsecurityjwtsignerhmac-getalgheader"><code>getAlgHeader()</code></h4>

```php
public function getAlgHeader(): string;
```

Return the value that is used for the "alg" header

<h4 id="encryptionsecurityjwtsignerhmac-sign"><code>sign()</code></h4>

```php
public function sign(
string $payload,
string $passphrase
): string;
```

Sign a payload using the passphrase

<h4 id="encryptionsecurityjwtsignerhmac-verify"><code>verify()</code></h4>

```php
public function verify(
string $source,
string $payload,
string $passphrase
): bool;
```

Verify a passed source with a payload and passphrase

## Encryption\Security\JWT\Signer\None

Class

No signing class

- **`Phalcon\Encryption\Security\JWT\Signer\None`** - implements [`Phalcon\Encryption\Security\JWT\Signer\SignerInterface`](#encryptionsecurityjwtsignersignerinterface)

### Method Summary

<ApiItem href="#encryptionsecurityjwtsignernone-getalgheader" visibility="public" name="getAlgHeader" returnType="string" params={[]}>
Return the value that is used for the "alg" header
</ApiItem>
<ApiItem href="#encryptionsecurityjwtsignernone-getalgorithm" visibility="public" name="getAlgorithm" returnType="string" params={[]}>
Return the algorithm used
</ApiItem>
<ApiItem href="#encryptionsecurityjwtsignernone-sign" visibility="public" name="sign" returnType="string" params={[{"type":"string","name":"payload","default":null},{"type":"string","name":"passphrase","default":null}]}>
Sign a payload using the passphrase
</ApiItem>
<ApiItem href="#encryptionsecurityjwtsignernone-verify" visibility="public" name="verify" returnType="bool" params={[{"type":"string","name":"source","default":null},{"type":"string","name":"payload","default":null},{"type":"string","name":"passphrase","default":null}]}>
Verify a passed source with a payload and passphrase
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtsignernone-getalgheader"><code>getAlgHeader()</code></h4>

```php
public function getAlgHeader(): string;
```

Return the value that is used for the "alg" header

<h4 id="encryptionsecurityjwtsignernone-getalgorithm"><code>getAlgorithm()</code></h4>

```php
public function getAlgorithm(): string;
```

Return the algorithm used

<h4 id="encryptionsecurityjwtsignernone-sign"><code>sign()</code></h4>

```php
public function sign(
string $payload,
string $passphrase
): string;
```

Sign a payload using the passphrase

<h4 id="encryptionsecurityjwtsignernone-verify"><code>verify()</code></h4>

```php
public function verify(
string $source,
string $payload,
string $passphrase
): bool;
```

Verify a passed source with a payload and passphrase

## Encryption\Security\JWT\Signer\SignerInterface

Interface

Interface for JWT Signer classes

- [`Phalcon\Contracts\Encryption\Security\JWT\Signer\Signer`](/5.20/api/phalcon_contracts/#contractsencryptionsecurityjwtsignersigner)
- **`Phalcon\Encryption\Security\JWT\Signer\SignerInterface`**

`Phalcon\Contracts\Encryption\Security\JWT\Signer\Signer`

## Encryption\Security\JWT\Token\AbstractItem

Abstract

Abstract helper class for Tokens

- **`Phalcon\Encryption\Security\JWT\Token\AbstractItem`**
- [`Phalcon\Encryption\Security\JWT\Token\Item`](#encryptionsecurityjwttokenitem)
- [`Phalcon\Encryption\Security\JWT\Token\Signature`](#encryptionsecurityjwttokensignature)

### Method Summary

<ApiItem href="#encryptionsecurityjwttokenabstractitem-getencoded" visibility="public" name="getEncoded" returnType="string" params={[]}>
</ApiItem>

### Properties

<ApiItem kind="property" visibility="protected" name="data" type="array" default="[]">
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwttokenabstractitem-getencoded"><code>getEncoded()</code></h4>

```php
public function getEncoded(): string;
```

## Encryption\Security\JWT\Token\Enum

Class

Constants for Tokens. It offers constants for Headers as well as Claims

@link https://tools.ietf.org/html/rfc7519

- **`Phalcon\Encryption\Security\JWT\Token\Enum`**

### Constants

<ApiItem kind="constant" name="ALGO" type="string" default="&quot;alg&quot;">
</ApiItem>
<ApiItem kind="constant" name="AUDIENCE" type="string" default="&quot;aud&quot;">
Claims
</ApiItem>
<ApiItem kind="constant" name="CONTENT_TYPE" type="string" default="&quot;cty&quot;">
</ApiItem>
<ApiItem kind="constant" name="EXPIRATION_TIME" type="string" default="&quot;exp&quot;">
</ApiItem>
<ApiItem kind="constant" name="ID" type="string" default="&quot;jti&quot;">
</ApiItem>
<ApiItem kind="constant" name="ISSUED_AT" type="string" default="&quot;iat&quot;">
</ApiItem>
<ApiItem kind="constant" name="ISSUER" type="string" default="&quot;iss&quot;">
</ApiItem>
<ApiItem kind="constant" name="NOT_BEFORE" type="string" default="&quot;nbf&quot;">
</ApiItem>
<ApiItem kind="constant" name="SUBJECT" type="string" default="&quot;sub&quot;">
</ApiItem>
<ApiItem kind="constant" name="TYPE" type="string" default="&quot;typ&quot;">
Headers
</ApiItem>

## Encryption\Security\JWT\Token\Item

Class

Storage class for a Token Item

- [`Phalcon\Encryption\Security\JWT\Token\AbstractItem`](#encryptionsecurityjwttokenabstractitem)
- **`Phalcon\Encryption\Security\JWT\Token\Item`**

### Method Summary

<ApiItem href="#encryptionsecurityjwttokenitem-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"array","name":"payload","default":null},{"type":"string","name":"encoded","default":null}]}>
Item constructor.
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokenitem-get" visibility="public" name="get" returnType="mixed|null" params={[{"type":"string","name":"name","default":null},{"type":"mixed","name":"defaultValue","default":"null"}]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokenitem-getpayload" visibility="public" name="getPayload" returnType="array" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokenitem-has" visibility="public" name="has" returnType="bool" params={[{"type":"string","name":"name","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwttokenitem-__construct"><code>__construct()</code></h4>

```php
public function __construct(
array $payload,
string $encoded
);
```

Item constructor.

<h4 id="encryptionsecurityjwttokenitem-get"><code>get()</code></h4>

```php
public function get(
string $name,
mixed $defaultValue = null
): mixed|null;
```

<h4 id="encryptionsecurityjwttokenitem-getpayload"><code>getPayload()</code></h4>

```php
public function getPayload(): array;
```

<h4 id="encryptionsecurityjwttokenitem-has"><code>has()</code></h4>

```php
public function has( string $name ): bool;
```

## Encryption\Security\JWT\Token\Parser

Class

Token Parser class.

It parses a token by validating if it is formed properly and splits it into
three parts. The headers are decoded, then the claims and finally the
signature. It returns a token object populated with the decoded information.

- **`Phalcon\Encryption\Security\JWT\Token\Parser`**

`InvalidArgumentException` · `Phalcon\Encryption\Security\JWT\Exceptions\InvalidClaims` · `Phalcon\Encryption\Security\JWT\Exceptions\InvalidHeader` · `Phalcon\Encryption\Security\JWT\Exceptions\MalformedJwtString` · `Phalcon\Encryption\Security\JWT\Exceptions\MissingJwtTypHeader` · `Phalcon\Support\Helper\Json\Decode` · `Phalcon\Traits\Php\Base64Trait`

### Method Summary

<ApiItem href="#encryptionsecurityjwttokenparser-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"Decode|null","name":"decode","default":"null"}]}>
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokenparser-parse" visibility="public" name="parse" returnType="Token" params={[{"type":"string","name":"token","default":null}]}>
Parse a token and return it
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwttokenparser-__construct"><code>__construct()</code></h4>

```php
public function __construct( Decode|null $decode = null );
```

<h4 id="encryptionsecurityjwttokenparser-parse"><code>parse()</code></h4>

```php
public function parse( string $token ): Token;
```

Parse a token and return it

## Encryption\Security\JWT\Token\Signature

Class

Signature class containing the encoded data and the hash.

- [`Phalcon\Encryption\Security\JWT\Token\AbstractItem`](#encryptionsecurityjwttokenabstractitem)
- **`Phalcon\Encryption\Security\JWT\Token\Signature`**

### Method Summary

<ApiItem href="#encryptionsecurityjwttokensignature-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"string","name":"hash","default":"\"\""},{"type":"string","name":"encoded","default":"\"\""}]}>
Signature constructor.
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokensignature-gethash" visibility="public" name="getHash" returnType="string" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwttokensignature-__construct"><code>__construct()</code></h4>

```php
public function __construct(
string $hash = "",
string $encoded = ""
);
```

Signature constructor.

<h4 id="encryptionsecurityjwttokensignature-gethash"><code>getHash()</code></h4>

```php
public function getHash(): string;
```

## Encryption\Security\JWT\Token\Token

Class

Token Class.

A container for Token related data. It stores the claims, headers, signature
and payload. It also calculates and returns the token string.

@property Item      $claims
@property Item      $headers
@property Signature $signature

@link https://tools.ietf.org/html/rfc7519

- **`Phalcon\Encryption\Security\JWT\Token\Token`**

`Phalcon\Encryption\Security\JWT\Signer\SignerInterface` · `Phalcon\Encryption\Security\JWT\Validator`

### Method Summary

<ApiItem href="#encryptionsecurityjwttokentoken-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"Item","name":"headers","default":null},{"type":"Item","name":"claims","default":null},{"type":"Signature","name":"signature","default":null}]}>
Token constructor.
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokentoken-getclaims" visibility="public" name="getClaims" returnType="Item" params={[]}>
Return the registered claims
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokentoken-getheaders" visibility="public" name="getHeaders" returnType="Item" params={[]}>
Return the registered headers
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokentoken-getpayload" visibility="public" name="getPayload" returnType="string" params={[]}>
Return the payload
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokentoken-getsignature" visibility="public" name="getSignature" returnType="Signature" params={[]}>
Return the signature
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokentoken-gettoken" visibility="public" name="getToken" returnType="string" params={[]}>
Return the token
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokentoken-validate" visibility="public" name="validate" returnType="array" params={[{"type":"Validator","name":"validator","default":null}]}>
Validate the token against the claims registered in the validator.
</ApiItem>
<ApiItem href="#encryptionsecurityjwttokentoken-verify" visibility="public" name="verify" returnType="bool" params={[{"type":"SignerInterface","name":"signer","default":null},{"type":"string","name":"key","default":null}]}>
Verify the signature
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwttokentoken-__construct"><code>__construct()</code></h4>

```php
public function __construct(
Item $headers,
Item $claims,
Signature $signature
);
```

Token constructor.

<h4 id="encryptionsecurityjwttokentoken-getclaims"><code>getClaims()</code></h4>

```php
public function getClaims(): Item;
```

Return the registered claims

<h4 id="encryptionsecurityjwttokentoken-getheaders"><code>getHeaders()</code></h4>

```php
public function getHeaders(): Item;
```

Return the registered headers

<h4 id="encryptionsecurityjwttokentoken-getpayload"><code>getPayload()</code></h4>

```php
public function getPayload(): string;
```

Return the payload

<h4 id="encryptionsecurityjwttokentoken-getsignature"><code>getSignature()</code></h4>

```php
public function getSignature(): Signature;
```

Return the signature

<h4 id="encryptionsecurityjwttokentoken-gettoken"><code>getToken()</code></h4>

```php
public function getToken(): string;
```

Return the token

<h4 id="encryptionsecurityjwttokentoken-validate"><code>validate()</code></h4>

```php
public function validate( Validator $validator ): array;
```

Validate the token against the claims registered in the validator.

Only claims that have a value in the validator are checked. A claim left
as null expresses no expectation and is skipped.

Security note: this method checks the claims only. It does not verify
the signature. A token accepted by validate() alone is unauthenticated.
Always also call verify() (or Validator::validateSignature()) and treat
an empty error array as valid only after the signature check passes.
A signature-aware default is planned for a future major version.

<h4 id="encryptionsecurityjwttokentoken-verify"><code>verify()</code></h4>

```php
public function verify(
SignerInterface $signer,
string $key
): bool;
```

Verify the signature

## Encryption\Security\JWT\Validator

Class

Class Validator

- **`Phalcon\Encryption\Security\JWT\Validator`**

`DateTimeImmutable` · `Phalcon\Encryption\Security\JWT\Exceptions\InvalidAudienceType` · `Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException` · `Phalcon\Encryption\Security\JWT\Signer\SignerInterface` · `Phalcon\Encryption\Security\JWT\Token\Enum` · `Phalcon\Encryption\Security\JWT\Token\Token` · `Phalcon\Time\Clock\ClockInterface`

### Method Summary

<ApiItem href="#encryptionsecurityjwtvalidator-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"Token","name":"token","default":null},{"type":"int","name":"timeShift","default":"0"},{"type":"ClockInterface|null","name":"clock","default":"null"}]}>
Validator constructor.
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-get" visibility="public" name="get" returnType="mixed|null" params={[{"type":"string","name":"claim","default":null}]}>
Return the value of a claim
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-geterrors" visibility="public" name="getErrors" returnType="array" params={[]}>
Return an array with validation errors (if any)
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-set" visibility="public" name="set" returnType="static" params={[{"type":"string","name":"claim","default":null},{"type":"mixed","name":"value","default":null}]}>
Set the value of a claim, for comparison with the token values
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-settoken" visibility="public" name="setToken" returnType="static" params={[{"type":"Token","name":"token","default":null}]}>
Set the token to be validated
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validateaudience" visibility="public" name="validateAudience" returnType="static" params={[{"type":"mixed","name":"audience","default":null}]}>
Validate the audience
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validateclaim" visibility="public" name="validateClaim" returnType="static" params={[{"type":"string","name":"name","default":null},{"type":"mixed","name":"value","default":null}]}>
Validate a claim
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validateexpiration" visibility="public" name="validateExpiration" returnType="static" params={[{"type":"int","name":"timestamp","default":null}]}>
Validate the expiration time of the token
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validateid" visibility="public" name="validateId" returnType="static" params={[{"type":"string|null","name":"id","default":"null"}]}>
Validate the id of the token
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validateissuedat" visibility="public" name="validateIssuedAt" returnType="static" params={[{"type":"int","name":"timestamp","default":null}]}>
Validate the issued at (iat) of the token
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validateissuer" visibility="public" name="validateIssuer" returnType="static" params={[{"type":"string|null","name":"issuer","default":"null"}]}>
Validate the issuer of the token
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validatenotbefore" visibility="public" name="validateNotBefore" returnType="static" params={[{"type":"int","name":"timestamp","default":null}]}>
Validate the notbefore (nbf) of the token
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validatesignature" visibility="public" name="validateSignature" returnType="static" params={[{"type":"SignerInterface","name":"signer","default":null},{"type":"string","name":"passphrase","default":null}]}>
Validate the signature of the token
</ApiItem>
<ApiItem href="#encryptionsecurityjwtvalidator-validatesubject" visibility="public" name="validateSubject" returnType="static" params={[{"type":"string|null","name":"subject","default":"null"}]}>
Validate the subject of the token
</ApiItem>

### Methods

<h4 id="encryptionsecurityjwtvalidator-__construct"><code>__construct()</code></h4>

```php
public function __construct(
Token $token,
int $timeShift = 0,
ClockInterface|null $clock = null
);
```

Validator constructor.

<h4 id="encryptionsecurityjwtvalidator-get"><code>get()</code></h4>

```php
public function get( string $claim ): mixed|null;
```

Return the value of a claim

<h4 id="encryptionsecurityjwtvalidator-geterrors"><code>getErrors()</code></h4>

```php
public function getErrors(): array;
```

Return an array with validation errors (if any)

<h4 id="encryptionsecurityjwtvalidator-set"><code>set()</code></h4>

```php
public function set(
string $claim,
mixed $value
): static;
```

Set the value of a claim, for comparison with the token values

<h4 id="encryptionsecurityjwtvalidator-settoken"><code>setToken()</code></h4>

```php
public function setToken( Token $token ): static;
```

Set the token to be validated

<h4 id="encryptionsecurityjwtvalidator-validateaudience"><code>validateAudience()</code></h4>

```php
public function validateAudience( mixed $audience ): static;
```

Validate the audience

<h4 id="encryptionsecurityjwtvalidator-validateclaim"><code>validateClaim()</code></h4>

```php
public function validateClaim(
string $name,
mixed $value
): static;
```

Validate a claim

<h4 id="encryptionsecurityjwtvalidator-validateexpiration"><code>validateExpiration()</code></h4>

```php
public function validateExpiration( int $timestamp ): static;
```

Validate the expiration time of the token

<h4 id="encryptionsecurityjwtvalidator-validateid"><code>validateId()</code></h4>

```php
public function validateId( string|null $id = null ): static;
```

Validate the id of the token

A null id expresses no expectation and is skipped.

<h4 id="encryptionsecurityjwtvalidator-validateissuedat"><code>validateIssuedAt()</code></h4>

```php
public function validateIssuedAt( int $timestamp ): static;
```

Validate the issued at (iat) of the token

A token issued at exactly $timestamp is valid. Only a token issued after
it, i.e. in the future, is rejected.

<h4 id="encryptionsecurityjwtvalidator-validateissuer"><code>validateIssuer()</code></h4>

```php
public function validateIssuer( string|null $issuer = null ): static;
```

Validate the issuer of the token

A null issuer expresses no expectation and is skipped.

<h4 id="encryptionsecurityjwtvalidator-validatenotbefore"><code>validateNotBefore()</code></h4>

```php
public function validateNotBefore( int $timestamp ): static;
```

Validate the notbefore (nbf) of the token

A token is valid at exactly $timestamp. Only a timestamp before the
"nbf" claim is rejected.

<h4 id="encryptionsecurityjwtvalidator-validatesignature"><code>validateSignature()</code></h4>

```php
public function validateSignature(
SignerInterface $signer,
string $passphrase
): static;
```

Validate the signature of the token

<h4 id="encryptionsecurityjwtvalidator-validatesubject"><code>validateSubject()</code></h4>

```php
public function validateSubject( string|null $subject = null ): static;
```

Validate the subject of the token

A null subject expresses no expectation and is skipped.

## Encryption\Security\Random

Class

Phalcon\Encryption\Security\Random

Secure random number generator class.

Provides secure random number generator which is suitable for generating
session key in HTTP cookies, etc.

`Phalcon\Encryption\Security\Random` could be mainly useful for:

- Key generation (e.g. generation of complicated keys)
- Generating random passwords for new user accounts
- Encryption systems

```php
$random = new \Phalcon\Encryption\Security\Random();

// Random binary string
$bytes = $random->bytes();

// Random hex string
echo $random->hex(10); // a29f470508d5ccb8e289
echo $random->hex(10); // 533c2f08d5eee750e64a
echo $random->hex(11); // f362ef96cb9ffef150c9cd
echo $random->hex(12); // 95469d667475125208be45c4
echo $random->hex(13); // 05475e8af4a34f8f743ab48761

// Random base62 string
echo $random->base62(); // z0RkwHfh8ErDM1xw

// Random base64 string
echo $random->base64(12); // XfIN81jGGuKkcE1E
echo $random->base64(12); // 3rcq39QzGK9fUqh8
echo $random->base64();   // DRcfbngL/iOo9hGGvy1TcQ==
echo $random->base64(16); // SvdhPcIHDZFad838Bb0Swg==

// Random URL-safe base64 string
echo $random->base64Safe();           // PcV6jGbJ6vfVw7hfKIFDGA
echo $random->base64Safe();           // GD8JojhzSTrqX7Q8J6uug
echo $random->base64Safe(8);          // mGyy0evy3ok
echo $random->base64Safe(null, true); // DRrAgOFkS4rvRiVHFefcQ==

// Random UUID (version 4) - returns a string
echo $random->uuid(); // db082997-2572-4e2c-a046-5eefe97b1235
echo $random->uuid(); // da2aa0e2-b4d0-4e3c-99f5-f5ef62c57fe2

// For other UUID versions (1, 3, 5, 6, 7) or object-based access use the
// Phalcon\Encryption\Security\Uuid factory instead:
//
// $uuid = new \Phalcon\Encryption\Security\Uuid();
// echo $uuid->v1(); // time-based
// echo $uuid->v6(); // reordered time-based (sortable)
// echo $uuid->v7(); // Unix-timestamp based (sortable)

// Random number between 0 and $len
echo $random->number(256); // 84
echo $random->number(256); // 79
echo $random->number(100); // 29
echo $random->number(300); // 40

// Random base58 string
echo $random->base58();   // 4kUgL2pdQMSCQtjE
echo $random->base58();   // Umjxqf7ZPwh765yR
echo $random->base58(24); // qoXcgmw4A9dys26HaNEdCRj9
echo $random->base58(7);  // 774SJD3vgP
```

This class partially borrows SecureRandom library from Ruby

@link https://ruby-doc.org/stdlib-2.2.2/libdoc/securerandom/rdoc/SecureRandom.html

- **`Phalcon\Encryption\Security\Random`**

`Phalcon\Encryption\Security\Exceptions\InvalidRandomInput`

### Method Summary

<ApiItem href="#encryptionsecurityrandom-base58" visibility="public" name="base58" returnType="string" params={[{"type":"int","name":"len","default":"16"}]}>
Generates a random base58 string
</ApiItem>
<ApiItem href="#encryptionsecurityrandom-base62" visibility="public" name="base62" returnType="string" params={[{"type":"int","name":"len","default":"16"}]}>
Generates a random base62 string
</ApiItem>
<ApiItem href="#encryptionsecurityrandom-base64" visibility="public" name="base64" returnType="string" params={[{"type":"int","name":"len","default":"16"}]}>
Generates a random base64 string
</ApiItem>
<ApiItem href="#encryptionsecurityrandom-base64safe" visibility="public" name="base64Safe" returnType="string" params={[{"type":"int","name":"len","default":"16"},{"type":"bool","name":"padding","default":"false"}]}>
Generates a random URL-safe base64 string
</ApiItem>
<ApiItem href="#encryptionsecurityrandom-bytes" visibility="public" name="bytes" returnType="string" params={[{"type":"int","name":"len","default":"16"}]}>
Generates a random binary string
</ApiItem>
<ApiItem href="#encryptionsecurityrandom-hex" visibility="public" name="hex" returnType="string" params={[{"type":"int","name":"len","default":"16"}]}>
Generates a random hex string
</ApiItem>
<ApiItem href="#encryptionsecurityrandom-number" visibility="public" name="number" returnType="int" params={[{"type":"int","name":"len","default":null}]}>
Generates a random number between 0 and $len
</ApiItem>
<ApiItem href="#encryptionsecurityrandom-uuid" visibility="public" name="uuid" returnType="string" params={[]}>
Generates a v4 random UUID (Universally Unique IDentifier)
</ApiItem>
<ApiItem href="#encryptionsecurityrandom-base" visibility="protected" name="base" returnType="string" params={[{"type":"string","name":"alphabet","default":null},{"type":"int","name":"base","default":null},{"type":"mixed","name":"number","default":"16"}]}>
Generates a random string based on the number ($base) of characters
</ApiItem>

### Methods

<h4 id="encryptionsecurityrandom-base58"><code>base58()</code></h4>

```php
public function base58( int $len = 16 ): string;
```

Generates a random base58 string

The result may contain alphanumeric characters except 0, O, I and l.

It is similar to `Phalcon\Encryption\Security\Random::base64()` but has been
modified to avoid both non-alphanumeric characters and letters which
might look ambiguous when printed.

```php
$random = new \Phalcon\Encryption\Security\Random();

echo $random->base58(); // 4kUgL2pdQMSCQtjE
```

@see    \Phalcon\Encryption\Security\Random:base64
@link   https://en.wikipedia.org/wiki/Base58

<h4 id="encryptionsecurityrandom-base62"><code>base62()</code></h4>

```php
public function base62( int $len = 16 ): string;
```

Generates a random base62 string

It is similar to `Phalcon\Encryption\Security\Random::base58()` but has been
modified to provide the largest value that can safely be used in URLs
without needing to take extra characters into consideration because it is
[A-Za-z0-9].

```php
$random = new \Phalcon\Encryption\Security\Random();

echo $random->base62(); // z0RkwHfh8ErDM1xw
```

@see    \Phalcon\Encryption\Security\Random:base58

<h4 id="encryptionsecurityrandom-base64"><code>base64()</code></h4>

```php
public function base64( int $len = 16 ): string;
```

Generates a random base64 string

The length of the result string is usually greater of $len.
Size formula: 4 * ($len / 3) rounded up to a multiple of 4.

```php
$random = new \Phalcon\Encryption\Security\Random();

echo $random->base64(12); // 3rcq39QzGK9fUqh8
```

<h4 id="encryptionsecurityrandom-base64safe"><code>base64Safe()</code></h4>

```php
public function base64Safe(
int $len = 16,
bool $padding = false
): string;
```

Generates a random URL-safe base64 string

The length of the result string is usually greater of $len.

By default, padding is not generated because "=" may be used as a URL
delimiter. The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also
used if $padding is true. See RFC 3548 for the definition of URL-safe
base64.

```php
$random = new \Phalcon\Encryption\Security\Random();

echo $random->base64Safe(); // GD8JojhzSTrqX7Q8J6uug
```

@link https://www.ietf.org/rfc/rfc3548.txt

<h4 id="encryptionsecurityrandom-bytes"><code>bytes()</code></h4>

```php
public function bytes( int $len = 16 ): string;
```

Generates a random binary string

The `Random::bytes` method returns a string and accepts as input an int
representing the length in bytes to be returned.

If $len is not specified, 16 is assumed. It may be larger in future.
The result may contain any byte: "x00" - "xFF".

```php
$random = new \Phalcon\Encryption\Security\Random();

$bytes = $random->bytes();
var_dump(bin2hex($bytes));
// Possible output: string(32) "00f6c04b144b41fad6a59111c126e1ee"
```

<h4 id="encryptionsecurityrandom-hex"><code>hex()</code></h4>

```php
public function hex( int $len = 16 ): string;
```

Generates a random hex string

The length of the result string is usually greater of $len.

```php
$random = new \Phalcon\Encryption\Security\Random();

echo $random->hex(10); // a29f470508d5ccb8e289
```

<h4 id="encryptionsecurityrandom-number"><code>number()</code></h4>

```php
public function number( int $len ): int;
```

Generates a random number between 0 and $len

Returns an integer: 0 &lt;= result &lt;= $len.

```php
$random = new \Phalcon\Encryption\Security\Random();

echo $random->number(16); // 8
```

<h4 id="encryptionsecurityrandom-uuid"><code>uuid()</code></h4>

```php
public function uuid(): string;
```

Generates a v4 random UUID (Universally Unique IDentifier)

The version 4 UUID is purely random (except the version). It does not
contain meaningful information such as MAC address, time, etc. See RFC
4122 for details of UUID.

Delegates to `Phalcon\Encryption\Security\Uuid::v4()`. For other UUID
versions or object-based access use that class directly.

```php
$random = new \Phalcon\Encryption\Security\Random();

echo $random->uuid(); // 1378c906-64bb-4f81-a8d6-4ae1bfcdec22
```

@link https://www.ietf.org/rfc/rfc4122.txt

<h4 id="encryptionsecurityrandom-base"><code>base()</code></h4>

```php
protected function base(
string $alphabet,
int $base,
mixed $number = 16
): string;
```

Generates a random string based on the number ($base) of characters
($alphabet).

## Encryption\Security\Uuid

Class

Factory that generates UUIDs of versions 1 through 7.

Each call creates a new immutable version object. Cast to string for the
UUID value; use the returned object for additional methods such as
getDateTime() or getNode().

- **`Phalcon\Encryption\Security\Uuid`**

`Phalcon\Encryption\Security\Uuid\Version1` · `Phalcon\Encryption\Security\Uuid\Version3` · `Phalcon\Encryption\Security\Uuid\Version4` · `Phalcon\Encryption\Security\Uuid\Version5` · `Phalcon\Encryption\Security\Uuid\Version6` · `Phalcon\Encryption\Security\Uuid\Version7`

### Method Summary

<ApiItem href="#encryptionsecurityuuid-v1" visibility="public" name="v1" returnType="Version1" params={[]}>
Generates a version 1 (time-based) UUID.
</ApiItem>
<ApiItem href="#encryptionsecurityuuid-v3" visibility="public" name="v3" returnType="Version3" params={[{"type":"string","name":"namespaceName","default":null},{"type":"string","name":"name","default":null}]}>
Generates a version 3 (name-based MD5) UUID.
</ApiItem>
<ApiItem href="#encryptionsecurityuuid-v4" visibility="public" name="v4" returnType="Version4" params={[]}>
Generates a version 4 (random) UUID.
</ApiItem>
<ApiItem href="#encryptionsecurityuuid-v5" visibility="public" name="v5" returnType="Version5" params={[{"type":"string","name":"namespaceName","default":null},{"type":"string","name":"name","default":null}]}>
Generates a version 5 (name-based SHA-1) UUID.
</ApiItem>
<ApiItem href="#encryptionsecurityuuid-v6" visibility="public" name="v6" returnType="Version6" params={[]}>
Generates a version 6 (reordered time-based) UUID.
</ApiItem>
<ApiItem href="#encryptionsecurityuuid-v7" visibility="public" name="v7" returnType="Version7" params={[]}>
Generates a version 7 (Unix timestamp) UUID.
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuid-v1"><code>v1()</code></h4>

```php
public function v1(): Version1;
```

Generates a version 1 (time-based) UUID.

<h4 id="encryptionsecurityuuid-v3"><code>v3()</code></h4>

```php
public function v3(
string $namespaceName,
string $name
): Version3;
```

Generates a version 3 (name-based MD5) UUID.

<h4 id="encryptionsecurityuuid-v4"><code>v4()</code></h4>

```php
public function v4(): Version4;
```

Generates a version 4 (random) UUID.

<h4 id="encryptionsecurityuuid-v5"><code>v5()</code></h4>

```php
public function v5(
string $namespaceName,
string $name
): Version5;
```

Generates a version 5 (name-based SHA-1) UUID.

<h4 id="encryptionsecurityuuid-v6"><code>v6()</code></h4>

```php
public function v6(): Version6;
```

Generates a version 6 (reordered time-based) UUID.

<h4 id="encryptionsecurityuuid-v7"><code>v7()</code></h4>

```php
public function v7(): Version7;
```

Generates a version 7 (Unix timestamp) UUID.

## Encryption\Security\Uuid\AbstractUuid

Abstract

Shared base for all UUID version objects.

- **`Phalcon\Encryption\Security\Uuid\AbstractUuid`** - implements [`Phalcon\Encryption\Security\Uuid\UuidInterface`](#encryptionsecurityuuiduuidinterface)
- [`Phalcon\Encryption\Security\Uuid\Version1`](#encryptionsecurityuuidversion1)
- [`Phalcon\Encryption\Security\Uuid\Version3`](#encryptionsecurityuuidversion3)
- [`Phalcon\Encryption\Security\Uuid\Version4`](#encryptionsecurityuuidversion4)
- [`Phalcon\Encryption\Security\Uuid\Version5`](#encryptionsecurityuuidversion5)
- [`Phalcon\Encryption\Security\Uuid\Version6`](#encryptionsecurityuuidversion6)
- [`Phalcon\Encryption\Security\Uuid\Version7`](#encryptionsecurityuuidversion7)

### Method Summary

<ApiItem href="#encryptionsecurityuuidabstractuuid-__tostring" visibility="public" name="__toString" returnType="string" params={[]}>
Returns the UUID string.
</ApiItem>
<ApiItem href="#encryptionsecurityuuidabstractuuid-jsonserialize" visibility="public" name="jsonSerialize" returnType="string" params={[]}>
Returns the UUID string for JSON serialisation.
</ApiItem>
<ApiItem href="#encryptionsecurityuuidabstractuuid-format" visibility="protected" name="format" returnType="string" params={[{"type":"string","name":"hex","default":null}]}>
Formats a 32-character hex string as a canonical UUID string.
</ApiItem>
<ApiItem href="#encryptionsecurityuuidabstractuuid-getnodeprovider" visibility="protected" name="getNodeProvider" returnType="NodeProviderInterface" params={[]}>
Returns the shared SysNodeProvider instance, creating it on first call.
</ApiItem>
<ApiItem href="#encryptionsecurityuuidabstractuuid-namespacetobytes" visibility="protected" name="namespaceToBytes" returnType="string" params={[{"type":"string","name":"uuid","default":null}]}>
Converts a canonical UUID string to its 16-byte binary representation.
</ApiItem>
<ApiItem href="#encryptionsecurityuuidabstractuuid-uuidtimestamptodatetime" visibility="protected" name="uuidTimestampToDateTime" returnType="\DateTimeImmutable" params={[{"type":"mixed","name":"timestamp","default":null}]}>
Converts a 60-bit UUID timestamp (100-ns intervals since UUID epoch) to
</ApiItem>

### Constants

<ApiItem kind="constant" name="MAX" type="string" default="&quot;ffffffff-ffff-ffff-ffff-ffffffffffff&quot;">
</ApiItem>
<ApiItem kind="constant" name="NIL" type="string" default="&quot;00000000-0000-0000-0000-000000000000&quot;">
</ApiItem>
<ApiItem kind="constant" name="TIME_OFFSET_INT" type="int" default="0x01B21DD213814000">
100-nanosecond intervals between UUID epoch (1582-10-15) and Unix epoch (1970-01-01).
</ApiItem>

### Properties

<ApiItem kind="property" visibility="protected" name="nodeProvider" type="NodeProviderInterface|null" default="null">
Cached SysNodeProvider instance - shared within the request via static.
</ApiItem>
<ApiItem kind="property" visibility="protected" name="uid" type="string" default="&quot;&quot;">
The generated UUID string.
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidabstractuuid-__tostring"><code>__toString()</code></h4>

```php
public function __toString(): string;
```

Returns the UUID string.

<h4 id="encryptionsecurityuuidabstractuuid-jsonserialize"><code>jsonSerialize()</code></h4>

```php
public function jsonSerialize(): string;
```

Returns the UUID string for JSON serialisation.

<h4 id="encryptionsecurityuuidabstractuuid-format"><code>format()</code></h4>

```php
protected function format( string $hex ): string;
```

Formats a 32-character hex string as a canonical UUID string.

<h4 id="encryptionsecurityuuidabstractuuid-getnodeprovider"><code>getNodeProvider()</code></h4>

```php
protected function getNodeProvider(): NodeProviderInterface;
```

Returns the shared SysNodeProvider instance, creating it on first call.
The static property means one discovery per request regardless of how
many VersionN objects are constructed.

<h4 id="encryptionsecurityuuidabstractuuid-namespacetobytes"><code>namespaceToBytes()</code></h4>

```php
protected function namespaceToBytes( string $uuid ): string;
```

Converts a canonical UUID string to its 16-byte binary representation.

<h4 id="encryptionsecurityuuidabstractuuid-uuidtimestamptodatetime"><code>uuidTimestampToDateTime()</code></h4>

```php
protected function uuidTimestampToDateTime( mixed $timestamp ): \DateTimeImmutable;
```

Converts a 60-bit UUID timestamp (100-ns intervals since UUID epoch) to
a DateTimeImmutable. Used by Version1 and Version6.

## Encryption\Security\Uuid\NodeProviderInterface

Interface

- [`Phalcon\Contracts\Encryption\Security\Uuid\NodeProvider`](/5.20/api/phalcon_contracts/#contractsencryptionsecurityuuidnodeprovider)
- **`Phalcon\Encryption\Security\Uuid\NodeProviderInterface`**

`Phalcon\Contracts\Encryption\Security\Uuid\NodeProvider`

## Encryption\Security\Uuid\RandomNodeProvider

Class

Generates a random 48-bit node with the multicast bit set.

Used as a fallback when no hardware MAC address is available.

@link https://www.ietf.org/rfc/rfc4122.txt Section 4.5

- **`Phalcon\Encryption\Security\Uuid\RandomNodeProvider`** - implements [`Phalcon\Encryption\Security\Uuid\NodeProviderInterface`](#encryptionsecurityuuidnodeproviderinterface)

### Method Summary

<ApiItem href="#encryptionsecurityuuidrandomnodeprovider-getnode" visibility="public" name="getNode" returnType="string" params={[]}>
Returns a random 12-character hex node with the multicast bit set.
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidrandomnodeprovider-getnode"><code>getNode()</code></h4>

```php
public function getNode(): string;
```

Returns a random 12-character hex node with the multicast bit set.

## Encryption\Security\Uuid\SysNodeProvider

Class

Discovers the hardware MAC address and returns it as a 12-character hex node.

Two-layer cache:
  1. Instance property  - free on all calls after the first within this instance.
  2. APCu               - cross-request within the same PHP-FPM worker (optional).

Falls back to RandomNodeProvider if no valid MAC address is found.

Platform support:
  Linux   - reads /sys/class/net/*\/address
  macOS   - passthru("ifconfig 2>&1")
  Windows - passthru("ipconfig /all 2>&1")
  FreeBSD - passthru("netstat -i -f link 2>&1")

- **`Phalcon\Encryption\Security\Uuid\SysNodeProvider`** - implements [`Phalcon\Encryption\Security\Uuid\NodeProviderInterface`](#encryptionsecurityuuidnodeproviderinterface)

`Phalcon\Traits\Php\FileTrait` · `Phalcon\Traits\Php\InfoTrait`

### Method Summary

<ApiItem href="#encryptionsecurityuuidsysnodeprovider-getnode" visibility="public" name="getNode" returnType="string" params={[]}>
Returns the hardware MAC address as a 12-character hex string.
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidsysnodeprovider-getnode"><code>getNode()</code></h4>

```php
public function getNode(): string;
```

Returns the hardware MAC address as a 12-character hex string.
Result is cached in the instance property and optionally in APCu.

## Encryption\Security\Uuid\TimeBasedUuidInterface

Interface

- [`Phalcon\Contracts\Encryption\Security\Uuid\TimeBasedUuid`](/5.20/api/phalcon_contracts/#contractsencryptionsecurityuuidtimebaseduuid)
- **`Phalcon\Encryption\Security\Uuid\TimeBasedUuidInterface`**

`Phalcon\Contracts\Encryption\Security\Uuid\TimeBasedUuid`

## Encryption\Security\Uuid\UuidInterface

Interface

Marker interface for UUID version adapters.

Also carries the standard RFC 4122 namespace UUIDs as constants.

- [`Phalcon\Contracts\Encryption\Security\Uuid\Uuid`](/5.20/api/phalcon_contracts/#contractsencryptionsecurityuuiduuid)
- **`Phalcon\Encryption\Security\Uuid\UuidInterface`**

`Phalcon\Contracts\Encryption\Security\Uuid\Uuid`

## Encryption\Security\Uuid\Version1

Class

Generates a version 1 (time-based) UUID.

The timestamp is the number of 100-nanosecond intervals since
October 15, 1582 00:00:00.00 UTC (the UUID epoch). The node is resolved
via SysNodeProvider (hardware MAC, APCu-cached) with RandomNodeProvider
as fallback.

@link https://www.ietf.org/rfc/rfc4122.txt

- [`Phalcon\Encryption\Security\Uuid\AbstractUuid`](#encryptionsecurityuuidabstractuuid)
- **`Phalcon\Encryption\Security\Uuid\Version1`** - implements [`Phalcon\Encryption\Security\Uuid\TimeBasedUuidInterface`](#encryptionsecurityuuidtimebaseduuidinterface)

### Method Summary

<ApiItem href="#encryptionsecurityuuidversion1-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"\\DateTimeInterface|null","name":"dateTime","default":"null"},{"type":"mixed","name":"node","default":"null"}]}>
</ApiItem>
<ApiItem href="#encryptionsecurityuuidversion1-getdatetime" visibility="public" name="getDateTime" returnType="\DateTimeImmutable" params={[]}>
Returns a DateTimeImmutable built from the UUID's embedded timestamp.
</ApiItem>
<ApiItem href="#encryptionsecurityuuidversion1-getnode" visibility="public" name="getNode" returnType="string" params={[]}>
Returns the 12-character hex node embedded in the UUID.
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidversion1-__construct"><code>__construct()</code></h4>

```php
public function __construct(
\DateTimeInterface|null $dateTime = null,
mixed $node = null
);
```

<h4 id="encryptionsecurityuuidversion1-getdatetime"><code>getDateTime()</code></h4>

```php
public function getDateTime(): \DateTimeImmutable;
```

Returns a DateTimeImmutable built from the UUID's embedded timestamp.

<h4 id="encryptionsecurityuuidversion1-getnode"><code>getNode()</code></h4>

```php
public function getNode(): string;
```

Returns the 12-character hex node embedded in the UUID.

## Encryption\Security\Uuid\Version3

Class

Generates a version 3 (name-based MD5) UUID.

Given a namespace UUID and a name string, produces a deterministic UUID
by hashing namespace bytes + name with MD5, then stamping version/variant.

@link https://www.ietf.org/rfc/rfc4122.txt

- [`Phalcon\Encryption\Security\Uuid\AbstractUuid`](#encryptionsecurityuuidabstractuuid)
- **`Phalcon\Encryption\Security\Uuid\Version3`**

### Method Summary

<ApiItem href="#encryptionsecurityuuidversion3-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"string","name":"namespaceName","default":null},{"type":"string","name":"name","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidversion3-__construct"><code>__construct()</code></h4>

```php
public function __construct(
string $namespaceName,
string $name
);
```

## Encryption\Security\Uuid\Version4

Class

Generates a version 4 (random) UUID.

All 122 non-fixed bits are random. Identical algorithm to
Phalcon\Encryption\Security\Random::uuid().

@link https://www.ietf.org/rfc/rfc4122.txt

- [`Phalcon\Encryption\Security\Uuid\AbstractUuid`](#encryptionsecurityuuidabstractuuid)
- **`Phalcon\Encryption\Security\Uuid\Version4`**

### Method Summary

<ApiItem href="#encryptionsecurityuuidversion4-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidversion4-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Encryption\Security\Uuid\Version5

Class

Generates a version 5 (name-based SHA-1) UUID.

Given a namespace UUID and a name string, produces a deterministic UUID
by hashing namespace bytes + name with SHA-1 (first 16 bytes used),
then stamping version/variant bits.

@link https://www.ietf.org/rfc/rfc4122.txt

- [`Phalcon\Encryption\Security\Uuid\AbstractUuid`](#encryptionsecurityuuidabstractuuid)
- **`Phalcon\Encryption\Security\Uuid\Version5`**

### Method Summary

<ApiItem href="#encryptionsecurityuuidversion5-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"string","name":"namespaceName","default":null},{"type":"string","name":"name","default":null}]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidversion5-__construct"><code>__construct()</code></h4>

```php
public function __construct(
string $namespaceName,
string $name
);
```

## Encryption\Security\Uuid\Version6

Class

Generates a version 6 (reordered time-based) UUID.

Uses the same 60-bit UUID timestamp as version 1 but rearranges the
fields so the most-significant time bits come first, producing UUIDs
that sort lexicographically in chronological order.

@link https://www.rfc-editor.org/rfc/rfc9562

- [`Phalcon\Encryption\Security\Uuid\AbstractUuid`](#encryptionsecurityuuidabstractuuid)
- **`Phalcon\Encryption\Security\Uuid\Version6`** - implements [`Phalcon\Encryption\Security\Uuid\TimeBasedUuidInterface`](#encryptionsecurityuuidtimebaseduuidinterface)

### Method Summary

<ApiItem href="#encryptionsecurityuuidversion6-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>
<ApiItem href="#encryptionsecurityuuidversion6-getdatetime" visibility="public" name="getDateTime" returnType="\DateTimeImmutable" params={[]}>
Returns a DateTimeImmutable built from the UUID's embedded timestamp.
</ApiItem>
<ApiItem href="#encryptionsecurityuuidversion6-getnode" visibility="public" name="getNode" returnType="string" params={[]}>
Returns the 12-character hex node embedded in the UUID.
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidversion6-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

<h4 id="encryptionsecurityuuidversion6-getdatetime"><code>getDateTime()</code></h4>

```php
public function getDateTime(): \DateTimeImmutable;
```

Returns a DateTimeImmutable built from the UUID's embedded timestamp.

<h4 id="encryptionsecurityuuidversion6-getnode"><code>getNode()</code></h4>

```php
public function getNode(): string;
```

Returns the 12-character hex node embedded in the UUID.

## Encryption\Security\Uuid\Version7

Class

Generates a version 7 (Unix timestamp) UUID per RFC 9562.

Layout (128 bits):
  unix_ts_ms (48) | ver=7 (4) | rand_a (12) | var=10 (2) | rand_b (62)

@link https://www.rfc-editor.org/rfc/rfc9562

- [`Phalcon\Encryption\Security\Uuid\AbstractUuid`](#encryptionsecurityuuidabstractuuid)
- **`Phalcon\Encryption\Security\Uuid\Version7`**

### Method Summary

<ApiItem href="#encryptionsecurityuuidversion7-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="encryptionsecurityuuidversion7-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

Source: https://docs.phalcon.io/5.20/api/phalcon_encryption/index.mdx
