class CryptoSecret

libsodium wrapper class for secret-key authenticated crypto

Methods

static int
KeyLength()

Returns the length of a key for use with this class

static int
NonceLength()

Returns the length of a nonce for use with this class

static int
OutputOverhead()

Returns the size overhead of an encrypted string over a plaintext one

static string
GenerateKey()

Generates a crypto key for use with this class

static string
GenerateNonce()

Generates a crypto nonce for use with this class

static string
Encrypt(string $data, string $nonce, string $key, string $extra = null)

Encrypts the given data

static string
Decrypt(string $data, string $nonce, string $key, string $extra = null)

Decrypts the given data

Details

at line 43
static int KeyLength()

Returns the length of a key for use with this class

Return Value

int

at line 46
static int NonceLength()

Returns the length of a nonce for use with this class

Return Value

int

at line 53
static int OutputOverhead()

Returns the size overhead of an encrypted string over a plaintext one

The size overhead exists because the crypto is authenticated

Return Value

int

at line 56
static string GenerateKey()

Generates a crypto key for use with this class

Return Value

string

at line 59
static string GenerateNonce()

Generates a crypto nonce for use with this class

Return Value

string

at line 70
static string Encrypt(string $data, string $nonce, string $key, string $extra = null)

Encrypts the given data

Parameters

string $data

the plaintext to encrypt

string $nonce

the crypto nonce to use

string $key

the crypto key to use

string $extra

extra data to include in authentication (must be provided at decrypt)

Return Value

string

an encrypted and authenticated ciphertext

See also

sodium_crypto_aead_xchacha20poly1305_ietf_encrypt()

at line 87
static string Decrypt(string $data, string $nonce, string $key, string $extra = null)

Decrypts the given data

Parameters

string $data

the ciphertext to decrypt

string $nonce

the nonce that was used to encrypt

string $key

the key that was used to encrypt

string $extra

the extra auth data used to encrypt

Return Value

string

the decrypted and authenticated plaintext

Exceptions

DecryptionFailedException

if decryption fails

See also

sodium_crypto_aead_xchacha20poly1305_ietf_decrypt()