SecretBox class

Framework\Crypto\SecretBox

Class SecretBox.

Defined in libraries/crypto/src/SecretBox.php

Properties #

$key
-
$nonce
-

$key

protected string $key

$nonce

protected string $nonce

Methods #

__construct()
SecretBox constructor.
decrypt()
Decrypts a secret box message ciphertext.
encrypt()
Encrypts a secret box message.
makeKey()
Makes a secret box key.
makeNonce()
Makes a secret box nonce with the correct length.
validatedLengths()
Validates key and nonce.

__construct()

public function __construct(string $key, string $nonce)

SecretBox constructor.

Parameters
  • string $key
  • string $nonce
throws
LengthException if key or nonce has not the required length

decrypt()

public function decrypt(string $ciphertext): string|false

Decrypts a secret box message ciphertext.

Parameters
  • string $ciphertext
Returns string|false
throws
SodiumException

encrypt()

public function encrypt(string $message): string

Encrypts a secret box message.

Parameters
  • string $message
Returns string
throws
SodiumException

makeKey()

public static function makeKey(): string

Makes a secret box key.

Returns string

makeNonce()

public static function makeNonce(): string

Makes a secret box nonce with the correct length.

Returns string
throws
Exception if fail to get random bytes

validatedLengths()

protected function validatedLengths(string $key, string $nonce): void

Validates key and nonce.

Parameters
  • string $key
  • string $nonce
Returns void
throws
LengthException if key or nonce has not the required length