Warning - some features on this page require a newer Browser or OS than the one that you are currently using. If you have a different browser available then open this page with it.
Encrypt / Decrypt Info Example Code
Using this Page
- This page allows you to encrypt text and decrypt encrypted text using FastSitePHP’s Encryption class.
- Each time you refresh the page a new key will be generated.
- Keys generated by this page are secure, will only be created once, and are not logged.
- If a key is lost then encrypted data cannot be recovered, so make sure to save your key if you are using this page for critical data.
- The text is encrypted and decrypted on the server with each button click; however both the key and text are not logged.
- Encryption uses different random numbers each time data is encrypted which is why encrypting the same text with the same key generates different encrypted text on each button click.
- The Encryption Algorithm used on this page (and the default for FastSitePHP) is Advanced Encryption Standard (AES) with a 256-bit key using CBC mode. Authentication is performed with HMAC using SHA-256.
- Half of the key (32 bytes / 256 bits) is used for encryption and the other half is used for authentication.
- The encrypted text (ciphertext) contains only encryption and HMAC bytes; it does not contain any headers or magic numbers to associate it with the encryption method.
// The data to encrypt can be in the format of: // [string, int, float, bool, array, object, and optionally null] // and when decrypted the same data type and value is returned. $crypto = new \FastSitePHP\Security\Crypto\Encryption(); $key = $crypto->generateKey(); $encrypted_text = $crypto->encrypt($data, $key); $decrypted_data = $crypto->decrypt($encrypted_text, $key); // Encrypt and Decrypt using a Password $crypto->keyType('password'); $encrypted_text = $crypto->encrypt($data, $password); $decrypted_data = $crypto->decrypt($encrypted_text, $password);