\Gishiki\Security\Encryption\SymmetricCryptography

This class represents an algorithm collection for the asymmetric encryption engine.

Note: This class uses OpenSSL for strong encryption

Summary

Methods
Properties
Constants
encrypt()
decrypt()
No public properties found
AES_CBC_128
AES_CBC_192
AES_CBC_256
No protected methods found
No protected properties found
N/A
checkKeySize()
No private properties found
N/A

Constants

AES_CBC_128

AES_CBC_128

AES_CBC_192

AES_CBC_192

AES_CBC_256

AES_CBC_256

Methods

encrypt()

encrypt(\Gishiki\Security\Encryption\Symmetric\SecretKey  $key, string  $message, string|null  $initVector = null, string  $algorithm = self::AES_CBC_128) : array

Encrypt the given content using the given secure key (that should be prepared using pbkdf2).

The resulting IV (automatically generated if null is passed) is base64 encoded.

The resulting encrypted content is base64 encoded.

Example usage: //prepare the secret key for the symmetric cipher $key = new SecretKey( ... ); //Note: the key is NOT the password

//encrypt the content $enc_result = Cryptography::encrypt($key, "this is the message to be encrypted");

//transmit the IV_base64 and Encryption to decrypt the content //if you used a cistom IV you don't need to pass the IV

Parameters

\Gishiki\Security\Encryption\Symmetric\SecretKey $key

the key to be used to encrypt the given message

string $message

the message to be encrypted

string|null $initVector

the base64 representation of the IV to be used (pick a random one if null)

string $algorithm

the name of the algorithm to be used

Throws

\InvalidArgumentException

one or more arguments are invalid

\Gishiki\Security\Encryption\Symmetric\SymmetricException

the error occurred while encrypting the content

Returns

array —

the base64 of the raw encryption result and the used IV

decrypt()

decrypt(\Gishiki\Security\Encryption\Symmetric\SecretKey  $key, string  $encryptedMessage, string  $initVector, string  $algorithm = self::AES_CBC_128) : string

Decrypt the given encrypted content using the given secure key (that should be prepared using pbkdf2 Ahead Of Time).

Example Usage: //this is the key encoded in hex format required to create the SecureKey $key_hex_encoded = " ... "; //make sure this is the key used when encrypting //Note: the key is NOT the password

//build the key $key = new SecretKey($key_hex_encoded);

//this is the IV encoded in base64: it is returned by the encrypt() function $initVector_base_encoded = " ... ";

//$message will hold the original plaintext message $message = Cryptography::decrypt($key, $encryptedMessage, $initVector_base_encoded);

Parameters

\Gishiki\Security\Encryption\Symmetric\SecretKey $key

the key that has been used to encrypt the message

string $encryptedMessage

the encryption result (must be base64-encoded)

string $initVector

the iv represented in base64

string $algorithm

the name of the algorithm to be used

Throws

\InvalidArgumentException

one or more arguments are invalid

\Gishiki\Security\Encryption\Symmetric\SymmetricException

the error occurred while decrypting the content

Returns

string —

the decrypted content

checkKeySize()

checkKeySize(array  $managedKey, string  $algorithm) : boolean

Check whether the given key can be used within the given algorithm.

Parameters

array $managedKey

the key in an exported format

string $algorithm

the used algorithm

Returns

boolean —

true only if the password is valid