1. Go to this page and download the library: Download farizfadian/phpcrypt 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/ */
farizfadian / phpcrypt example snippets
use PHPCrypt\Encryptor;
// Create encryptor with password
$enc = new Encryptor('mySecretPassword');
// Encrypt
$encrypted = $enc->encryptWithPrefix('db_password_123');
echo $encrypted; // ENC(base64encodedvalue...)
// Decrypt
$decrypted = $enc->decryptPrefixed($encrypted);
echo $decrypted; // db_password_123
use PHPCrypt\ConfigLoader;
// .env file:
// DATABASE_HOST=localhost
// DATABASE_PASSWORD=ENC(AbCdEf123456...)
$loader = new ConfigLoader(getenv('PHPCRYPT_PASSWORD'));
$config = $loader->loadEnvFile('.env');
echo $config['DATABASE_PASSWORD']; // actual_password
use PHPCrypt\Encryptor;
use PHPCrypt\JasyptEncryptor;
use PHPCrypt\JasyptStrongEncryptor;
// RECOMMENDED: For new PHP projects
$enc = new Encryptor($password);
// For compatibility with Java Jasypt (default algorithm)
$enc = new JasyptEncryptor($password);
// For compatibility with Java Jasypt (strong encryption)
$enc = new JasyptStrongEncryptor($password);
use PHPCrypt\JasyptEncryptor;
// Your Java application.properties has:
// db.password=ENC(xxxFromJavaxxx)
$enc = new JasyptEncryptor($samePasswordAsJava);
$decrypted = $enc->decryptPrefixed('ENC(xxxFromJavaxxx)'); // ✅ Works!
use PHPCrypt\JasyptEncryptor;
// Use JasyptEncryptor so all languages can read
$enc = new JasyptEncryptor($sharedPassword);
$encrypted = $enc->encryptWithPrefix('shared_secret');
// This ENC(...) value can be decrypted by:
// - PHP: using JasyptEncryptor
// - Go: using gocrypt.NewJasyptEncryptor
// - Python: using pycrypt.JasyptEncryptor
// - Node.js: using nodecrypt.JasyptEncryptor
// - Java: using Jasypt library
use PHPCrypt\ConfigLoader;
$loader = new ConfigLoader($password);
$config = $loader->loadEnvFile('config.env');
echo $config['DATABASE_PASSWORD']; // decrypted value
$config = $loader->loadJson('config.json');
$loader->setToEnv('.env');
// Now use getenv()
echo getenv('DATABASE_PASSWORD');
use PHPCrypt\Utils;
if (Utils::isEncrypted($value)) {
$decrypted = $enc->decryptPrefixed($value);
}
// In config/app.php or a service provider
use PHPCrypt\JasyptEncryptor;
$enc = new JasyptEncryptor(env('PHPCRYPT_PASSWORD'));
$dbPassword = $enc->decryptPrefixed(env('DATABASE_PASSWORD'));
// Or create a facade/service
// In services.yaml
services:
PHPCrypt\JasyptEncryptor:
arguments:
$password: '%env(PHPCRYPT_PASSWORD)%'