Framework\Cipher

Cipher class helps you to encrypt or decrypt text.

Methods

  • base64EncodeSafe (string $string) : string
  • base64DecodeSafe (string $string) : string
  • encrypt (string $string, string $key) : string
  • decrypt (string $string, string $key) : string

Note: encrypt() and decrypt() are based on OpenSSL library.

Examples

Use this code to encrypt a string.

$hash = Cipher::encrypt('mypassword', 'DHEbSK1KmU3MQn...');

Use this code to decrypt a string.

if (Cipher::decrypt($hash,  'DHEbSK1KmU3MQn...')) {
    // ...
}

base64EncodeSafe and base64DecodeSafe return base64 encoded strings with special characters removed.