1. Go to this page and download the library: Download temant/encryption-manager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
temant / encryption-manager example snippets
use Temant\EncryptionManager\EncryptionManager;
// The secret should be a high-entropy value (e.g. a 32+ byte random string from your
// app's secrets manager), not a human password.
$encryption = new EncryptionManager('your-high-entropy-app-secret');
$encrypted = $encryption->encryptString('Hello, World!');
$decrypted = $encryption->decryptString($encrypted);
echo "Encrypted: $encrypted\n";
echo "Decrypted: $decrypted\n";
use Temant\EncryptionManager\Crypto\EncryptionCipher;
use Temant\EncryptionManager\Crypto\EncryptionConfig;
$config = new EncryptionConfig(
cipher: EncryptionCipher::AES_128_GCM, // or AES_256_GCM (default)
pbkdf2Iterations: 250_000, // default: 150_000
saltBytes: 16, // default: 16
tagBytes: 16, // default: 16
hkdfInfo: 'my-app-name', // default: "temant-encryption"
);
$encryption = new EncryptionManager('your-app-secret', $config);
$encryption = new EncryptionManager('current-secret');
$oldPayload = $encryption->encryptString('archived data');
// Later, e.g. during a scheduled secret rotation:
$encryption->updateSecret('new-secret'); // old-secret is retired, not discarded
$encryption->decryptString($oldPayload); // still works (retired key)
$encryption->encryptString('new data'); // uses new-secret
$encryption = new EncryptionManager('current-secret', retiredSecrets: ['secret-from-2025-q4']);
// or:
$encryption->addRetiredSecret('secret-from-2025-q4');
// To permanently drop the keyring (old data becomes undecryptable):
$encryption->clearRetiredSecrets();
use Temant\EncryptionManager\EncryptionException;
try {
$encryption->decryptString($payload, $password);
} catch (EncryptionException $e) {
// Never assume a caught exception means "wrong password" specifically —
// the same exception type covers tampering, corruption, and config mismatches.
log($e->getMessage());
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.