\Gishiki\Security\Encryption\SymmetricSecretKey

This class represents a secret key for the symmetric encryption engine.

Note: This class uses OpenSSL for strong encryption

Summary

Methods
Properties
Constants
generate()
__construct()
export()
__toString()
__invoke()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$key
$keyLength
N/A

Properties

$key

$key : string

Type

string — the key in the native format

$keyLength

$keyLength : integer

Type

integer — the key length (in bytes)

Methods

generate()

generate(string  $password, integer  $keyLength = 16) : string

Generate the hexadecimal representation of a secure key using a salt algorithm in order to derive it from the given password.

Note: once generated the key cannot be retrieved... you MUST save the key for future usage.

Parameters

string $password

the password to be derived

integer $keyLength

the final length of the key (in bytes)

Throws

\InvalidArgumentException

invalid arguments have been passed

\Gishiki\Security\Hashing\HashingException

the error occurred while generating the requested hashing algorithm

Returns

string —

an hex representation of the generated key

__construct()

__construct(string  $key) 

Create an encryption key using the given serialized key.

A serialized key is the hexadecimal representation of key.

You can use the generate() function to retrive a really secure key from the password (the same key derivation algorithm that openssl internally uses).

Usage example:

//generate a secure pbkdf2-derived key and use it as the encryption key $my_key = new SecretKey(SecretKey::generate("mypassword"));

//you MUST save the generated key, because it won't be possible to //generate the same key once again (even using the same password)! $precious_key = (string) $my_key;

Parameters

string $key

the password to be used in a HEX encoded format

export()

export() : string

Export the currently loaded key.

Returns

string —

the hex representation of the loaded key

__toString()

__toString() : string

Proxy call to the export() function.

Returns

string —

the serialized key

__invoke()

__invoke() : array

Export a reference to the native private key and its length in bits.

Returns

array —

the array that contains the key and its legth (in bytes)