Box class
Framework\Crypto\Box
Class Box.
Defined in libraries/crypto/src/Box.php
Properties #
- $secretKey
- -
- $publicKey
- -
- $nonce
- -
$secretKey
protected string $secretKey
$publicKey
protected string $publicKey
$nonce
protected ?string $nonce
Methods #
- __construct()
- Box constructor.
- decrypt()
- Decrypts a box message ciphertext.
- encrypt()
- Encrypts a box message.
- makeKeyPair()
- Makes a keypair.
- makeNonce()
- Makes a box nonce with the correct length.
- makePublicKey()
- Makes the public key from a keypair.
- makeSecretKey()
- Makes the secret key from a keypair.
- getKeyPair()
- Gets the keypair from the secret and public keys.
- getNonce()
- -
- validateNonce()
- Validates a nonce.
__construct()
public function __construct(string $secretKey, string $publicKey, ?string $nonce = NULL)
Box constructor.
Parameters
- string $secretKey
- string $publicKey
- ?string $nonce
decrypt()
public function decrypt(string $ciphertext, ?string $nonce = NULL): string|false
Decrypts a box message ciphertext.
Parameters
- string $ciphertext
- ?string $nonce - The message nonce or null to use the nonce set int the constructor
Returns
string|false
encrypt()
public function encrypt(string $message, ?string $nonce = NULL): string
Encrypts a box message.
Parameters
- string $message
- ?string $nonce - The message nonce or null to use the nonce set int the constructor
Returns
string
makeKeyPair()
public static function makeKeyPair(): string
Makes a keypair.
Returns
string
makeNonce()
public static function makeNonce(): string
Makes a box nonce with the correct length.
Returns
string
makePublicKey()
public static function makePublicKey(string $keyPair): string
Makes the public key from a keypair.
Parameters
- string $keyPair
Returns
string
makeSecretKey()
public static function makeSecretKey(string $keyPair): string
Makes the secret key from a keypair.
Parameters
- string $keyPair
Returns
string
getKeyPair()
protected function getKeyPair(): string
Gets the keypair from the secret and public keys.
Returns
string
getNonce()
protected function getNonce(?string $nonce): string
Parameters
- ?string $nonce
Returns
string
validateNonce()
protected function validateNonce(string $nonce): void
Validates a nonce.
Parameters
- string $nonce
Returns
void