Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
PSL is a security library for PHP. It provides advanced random data generation, encryption utilities as well as certificate generation and signing.
branch: master

Merge pull request #4 from defuse/patch-1

Make example use AES instead of MCRYPT_RIJNDAEL_256
latest commit 8ad5f9f668
@kaisellgren authored
Failed to load latest commit information.
Security Update Randomizer.php
tests Initial commit. Make example use AES instead of MCRYPT_RIJNDAEL_256
license.txt Initial commit.

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());
Something went wrong with that request. Please try again.