Aplus Framework Docs

Box
in package
Uses BoxTrait

Class Box.

Table of Contents

$nonce  : string|null
$publicKey  : string
$secretKey  : string
__construct()  : mixed
Box constructor.
decrypt()  : false|string
Decrypts a box message ciphertext.
encrypt()  : string
Encrypts a box message.
makeKeyPair()  : string
Makes a keypair.
makeNonce()  : string
Makes a box nonce with the correct length.
makePublicKey()  : string
Makes the public key from a keypair.
makeSecretKey()  : string
Makes the secret key from a keypair.
getKeyPair()  : string
Gets the keypair from the secret and public keys.
getNonce()  : string
validateNonce()  : void
Validates a nonce.

Properties

$nonce

protected string|null $nonce

$publicKey

protected string $publicKey

$secretKey

protected string $secretKey

Methods

__construct()

Box constructor.

public __construct(string $secretKey, string $publicKey[, string|null $nonce = null ]) : mixed
Parameters
$secretKey : string
$publicKey : string
$nonce : string|null = null
Tags
see
BoxTrait::makePublicKey()
see
BoxTrait::makeSecretKey()
see
BoxTrait::makeNonce()
throws
LengthException

if nonce is set has not the required length

Return values
mixed

decrypt()

Decrypts a box message ciphertext.

public decrypt(string $ciphertext[, string|null $nonce = null ]) : false|string
Parameters
$ciphertext : string
$nonce : string|null = null

The message nonce or null to use the nonce set int the constructor

Tags
throws
LengthException

if nonce is set and has not the required length

throws
LogicException

if nonce param is null and nonce was not set in the constructor

throws
SodiumException
Return values
false|string

encrypt()

Encrypts a box message.

public encrypt(string $message[, string|null $nonce = null ]) : string
Parameters
$message : string
$nonce : string|null = null

The message nonce or null to use the nonce set int the constructor

Tags
throws
LengthException

if nonce is set and has not the required length

throws
LogicException

if nonce param is null and nonce was not set in the constructor

throws
SodiumException
Return values
string

makeKeyPair()

Makes a keypair.

public static makeKeyPair() : string
Tags
throws
SodiumException
Return values
string

makeNonce()

Makes a box nonce with the correct length.

public static makeNonce() : string
Tags
throws
Exception

if fail to get random bytes

Return values
string

makePublicKey()

Makes the public key from a keypair.

public static makePublicKey(string $keyPair) : string
Parameters
$keyPair : string
Tags
see
BoxTrait::makeKeyPair()
throws
SodiumException
Return values
string

makeSecretKey()

Makes the secret key from a keypair.

public static makeSecretKey(string $keyPair) : string
Parameters
$keyPair : string
Tags
see
BoxTrait::makeKeyPair()
throws
SodiumException
Return values
string

getKeyPair()

Gets the keypair from the secret and public keys.

protected getKeyPair() : string
Tags
throws
SodiumException
Return values
string

getNonce()

protected getNonce(string|null $nonce) : string
Parameters
$nonce : string|null
Tags
throws
LengthException

if nonce is set and has not the required length

throws
LogicException

if nonce param is null and nonce was not set in constructor

Return values
string

validateNonce()

Validates a nonce.

protected validateNonce(string $nonce) : void
Parameters
$nonce : string
Tags
throws
LengthException

if nonce has not the required length

Return values
void

Search results