Class: SodiumCipher
Full name: Azera\Security\Crypt\SodiumCipher
ChaCha20-Poly1305 (IETF) authenticated encryption via libsodium.
Preferred default: it is the AEAD built into modern PHP, has no padding oracle, and is constant-time on all supported platforms.
Payload layout, inside the CipherPayload envelope:
nonce (12 bytes) || ciphertext || tag (16 bytes)
Public Constants
- ID =
'sodium-chacha20poly1305.v1'
Public methods
id() ·
public function id(): string
Return value
- Type:
string
isAvailable() ·
public function isAvailable(): bool
Return value
- Type:
bool
encrypt() ·
public function encrypt(string $plaintext, string $key, string $associated = ''): string
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$plaintext |
string | - | |
$key |
string | - | |
$associated |
string | '' |
Return value
- Type:
string
decrypt() ·
public function decrypt(string $payload, string $key, string $associated = ''): string|null
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$payload |
string | - | |
$key |
string | - | |
$associated |
string | '' |
Return value
- Type:
string|null