PSL is a security library for PHP. It provides advanced random data generation, encryption utilities as well as certificate generation and signing.
PHP Shell
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

PHP Security Library

This library provides you a handful set of useful helper methods and classes related to security.


Encrypt data securely.
use \PSL\Encrypter;

$confidentalText = 'I am using PSL';

$cipherText = Encrypter::encrypt(MCRYPT_RIJNDAEL_128, $confidentalText);

// $cipherText is an instance of \PSL\CipherText.
// To extract, do something like this:
$key = $cipherText->key;
$plainText = Encrypter::decrypt($cipherText, $key);

// $plainText is now same as $confidentalText.
Generate strong random data.
use \PSL\Randomizer;

$data = Randomizer::getRandomBytes(32); // 32 bytes.

$randomFloat = Randomizer::getRandomFloat();

Things like random float generation is more conplex than what it might seem initially and therefore it's nice to be able to use a library for that.

Generate a certificate.
use \PSL\KeyPair;
use \PSL\Certificate;

$keyPair = new KeyPair();

$details = array(
    "countryName" => "FI",
    "stateOrProvinceName" => "Southern Finland",
    "localityName" => "Lahti",
    "organizationName" => "N/A",
    "organizationalUnitName" => "N/A",
    "commonName" => "localhost",
    "emailAddress" => ""

$certificate = new Certificate($details, $keyPair);


file_put_contents('my.crt', $certificate->export());