class Crypt

Crypt is a Joomla Platform class for handling basic encryption/decryption of data.

Methods

__construct( CipherInterface $cipher = null, Key $key = null)

Object Constructor takes an optional key to be used for encryption/decryption. If no key is given then the secret word from the configuration object is used.

string
decrypt( string $data)

Method to decrypt a data string.

string
encrypt( string $data)

Method to encrypt a data string.

Key
generateKey( array $options = array())

Method to generate a new encryption key[/pair] object.

setKey( Key $key)

Method to set the encryption key[/pair] object.

static  string
genRandomBytes( integer $length = 16)

Generate random bytes.

static  boolean
timingSafeCompare( string $known, string $unknown)

A timing safe comparison method.

static  boolean
hasStrongPasswordSupport()

Tests for the availability of updated crypt().

static  integer
safeStrlen( string $str)

Safely detect a string's length

static  string
safeSubstr( string $str, integer $start, integer $length = null)

Safely extract a substring

Details

__construct( CipherInterface $cipher = null, Key $key = null)

Object Constructor takes an optional key to be used for encryption/decryption. If no key is given then the secret word from the configuration object is used.

Parameters

CipherInterface $cipher The encryption cipher object.
Key $key The encryption key[/pair)].

string decrypt( string $data)

Method to decrypt a data string.

Parameters

string $data The encrypted string to decrypt.

Return Value

string The decrypted data string.

Exceptions

InvalidArgumentException

string encrypt( string $data)

Method to encrypt a data string.

Parameters

string $data The data string to encrypt.

Return Value

string The encrypted data string.

Key generateKey( array $options = array())

Method to generate a new encryption key[/pair] object.

Parameters

array $options Key generation options.

Return Value

Key

Crypt setKey( Key $key)

Method to set the encryption key[/pair] object.

Parameters

Key $key The key object to set.

Return Value

Crypt

static string genRandomBytes( integer $length = 16)

Generate random bytes.

Parameters

integer $length Length of the random data to generate

Return Value

string Random binary data

static boolean timingSafeCompare( string $known, string $unknown)

A timing safe comparison method.

This defeats hacking attempts that use timing based attack vectors.

NOTE: Length will leak.

Parameters

string $known A known string to check against.
string $unknown An unknown string to check.

Return Value

boolean True if the two strings are exactly the same.

static boolean hasStrongPasswordSupport()

Tests for the availability of updated crypt().

Based on a method by Anthony Ferrera

Return Value

boolean Always returns true since 3.3

static integer safeStrlen( string $str)

Safely detect a string's length

This method is derived from \ParagonIE\Halite\Util::safeStrlen()

Parameters

string $str String to check the length of

Return Value

integer

Exceptions

RuntimeException

static string safeSubstr( string $str, integer $start, integer $length = null)

Safely extract a substring

This method is derived from \ParagonIE\Halite\Util::safeSubstr()

Parameters

string $str The string to extract the substring from
integer $start The starting position to extract from
integer $length The length of the string to return

Return Value

string