Class Phalcon\Crypt

implements Phalcon\CryptInterface

Source on GitHub

Provides encryption facilities to phalcon applications


$crypt = new Phalcon\Crypt();

$key = 'le password';
$text = 'This is a secret text';

$encrypted = $crypt->encrypt($text, $key);

echo $crypt->decrypt($encrypted, $key);


public Phalcon\Encrypt setMethod (string $method)

Sets the cipher method

public string getMethod ()

Returns the current cipher method

public Phalcon\Encrypt setKey (string $key)

Sets the encryption key

public string getKey ()

Returns the encryption key

public Phalcon\CryptInterface setOptions (int $options)

Sets the options

public int getOptions ()

Returns the options

public string encrypt (string $text, [string $key], [unknown $options])

Encrypts a text


$encrypted = $crypt->encrypt("Ultra-secret text", "encrypt password");

public string decrypt (string $text, [string $key], [int $options])

Decrypts an encrypted text


echo $crypt->decrypt($encrypted, "decrypt password");

public string encryptBase64 (string $text, [string $key], [unknown $safe])

Encrypts a text returning the result as a base64 string

public string decryptBase64 (string $text, [string $key], [unknown $safe])

Decrypt a text that is coded as a base64 string

public array getAvailableMethods ()

Returns a list of available modes

public beforeEncrypt (callable $handler)

Adds a internal hooks before encrypts a text

public afterEncrypt (callable $handler)

Adds a internal hooks after encrypts a text

public beforeDecrypt (callable $handler)

Adds a internal hooks before decrypts an encrypted text

public afterDecrypt (callable $handler)

Adds a internal hooks after decrypts an encrypted text