sFire PHP Framework

Encrypt / Decrypt / Hashings

Fire\Hash\Hash provides an easy interface for encrypting/decrypting and hashing strings.

Note: sFire\Hash\Hash uses the open_ssl library.

In this section we will handle:

  • How to encrypt a string
  • How to decrypt a string
  • How to create a hash
  • How to validate a hash

Encryption

To encrypt a string you may use the encrypt method. This methods accepts two parameters.

Parameters
Hash :: encrypt(string $message, string $key);
Example
$encrypted = Hash :: encrypt('Hello world!', 'H6DqnA9N52mDpa63c');

Decryption

To decrypt a String what is encrypted with the encrypt method, you can use the decrypt method. This methods accepts two parameters.

Parameters
Hash :: decrypt(string $message, string $key);

Hashing

To hash a string you can use the hash method. This methods accepts one parameter.

Parameters
Hash :: hash(string $message);

Example:

$hash = Hash :: hash('Hello world!');

Validate hash

Verifies that data matches a hash. To validate a hashed String you can use the validateHash method. This methods accepts two parameters. The first parameter is a String that will be matched against the second String and already hashed parameter.

Parameters
Hash :: validateHash(string $data, string $hash);
Example
use sFire\Hash\Hash;

$hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';
$validate = Hash :: validateHash('rasmuslerdorf', $hash);

if(true === $validate) {
    //Hash is valid
}