class CryptoAuth

libsodium wrapper class for authentication-only crypto

Methods

static int
KeyLength()

Returns the length of a key for use with this class

static string
GenerateKey()

Generates a crypto key for use with this class

static string
MakeAuthCode(string $message, string $key)

Creates an authentication code (MAC) from a message and key

static bool
TryCheckAuthCode(string $mac, string $message, string $key)

Tries to authenticate a message using a secret key

static void
CheckAuthCode(string $mac, string $message, string $key)

Same as TryCheckAuthCode() but throws an exception on failure

Details

at line 151
static int KeyLength()

Returns the length of a key for use with this class

Return Value

int

at line 154
static string GenerateKey()

Generates a crypto key for use with this class

Return Value

string

at line 162
static string MakeAuthCode(string $message, string $key)

Creates an authentication code (MAC) from a message and key

Parameters

string $message

the message to create the MAC for

string $key

the secret key to use for creating the MAC

Return Value

string

the message authentication code (MAC)

at line 176
static bool TryCheckAuthCode(string $mac, string $message, string $key)

Tries to authenticate a message using a secret key

Parameters

string $mac

the message authentication code

string $message

the message to verify

string $key

the key used in creating the MAC

Return Value

bool

true if authentication succeeds

at line 188
static void CheckAuthCode(string $mac, string $message, string $key)

Same as TryCheckAuthCode() but throws an exception on failure

Parameters

string $mac
string $message
string $key

Return Value

void

Exceptions

DecryptionFailedException

if authentication fails

See also

CryptoAuth::TryCheckAuthCode