PHP Classes

Easy PHP RSA Library: RSA data encryption and decryption using phpseclib

Recommend this page to a friend!
  Info   View files Documentation   View files View files (19)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 51 All time: 10,653 This week: 455Up
Version License PHP version Categories
easyrsa 1.0.0MIT/X Consortium ...5PHP 5, Cryptography
Description 

Author

This package implements RSA data encryption and decryption using phpseclib.

It uses the phpseclib to implement several types of RSA cryptography functions. Currently it can:

- Create public and private key pairs
- Encrypt data with the public key
- Decrypt data with the secret key and the cipher
- Generate a signature of a data block using the public key
- Verify if a signature of data block is valid using the private key

Picture of Scott Arciszewski
  Performance   Level  
Name: Scott Arciszewski <contact>
Classes: 37 packages by
Country: United States United States
Age: ???
All time rank: 1178170 in United States United States
Week rank: 10 Up1 in United States United States Up
Innovation award
Innovation award
Nominee: 28x

Winner: 1x

Documentation

EasyRSA

Build Status

Simple and Secure Wrapper for phpseclib.

Important!

For better security, you want to use libsodium, not EasyRSA.

Motivation

Although the long-term security of RSA is questionable (at best) given the advances in index calculus attacks, there are many issues with how RSA is implemented in popular PHP cryptography libraries that make it vulnerable to attacks today.

Thanks to the folks who developed phpseclib, it's possible to use secure RSA in PHP. However, it's not user-friendly enough for the average PHP developer to use to its full potential. So we took it upon ourselves to offer a user-friendly interface instead.

EasyRSA is MIT licensed and brought to you by the secure PHP development team at Paragon Initiative Enterprises.

How to use this library?

composer require paragonie/easyrsa

Generating RSA key pairs

You can generate 2048-bit keys (or larger) using EasyRSA. The default size is 2048.

<?php
use ParagonIE\EasyRSA\KeyPair;

$keyPair = KeyPair::generateKeyPair(4096);

$secretKey = $keyPair->getPrivateKey();
$publicKey = $keyPair->getPublicKey();

Getting the Raw Key

<?php
/ @var \ParagonIE\EasyRSA\PublicKey $publicKey */
var_dump($publicKey->getKey());

Encrypting/Decrypting a Message

<?php
use ParagonIE\EasyRSA\EasyRSA;

$message = "test";
/ @var \ParagonIE\EasyRSA\PublicKey $publicKey */
/ @var \ParagonIE\EasyRSA\PrivateKey $secretKey */

$ciphertext = EasyRSA::encrypt($message, $publicKey);

$plaintext = EasyRSA::decrypt($ciphertext, $secretKey);

Signing/Verifying a Message

<?php
use ParagonIE\EasyRSA\EasyRSA;

$message = "test";
/ @var \ParagonIE\EasyRSA\PublicKey $publicKey */
/ @var \ParagonIE\EasyRSA\PrivateKey $secretKey */

$signature = EasyRSA::sign($message, $secretKey);

if (EasyRSA::verify($message, $signature, $publicKey)) {
    // Signature is valid!
}

Compatibility

EasyRSA is only compatible with itself. It is not compatible with OpenGPG (GnuPG, Mailvelope, etc.) You'll want GPG-Mailer instead.

What Does it Do Under the Hood?

  • Encryption (KEM+DEM) * Generates an random secret value * Encrypts the random secret value with your RSA public key, using PHPSecLib (RSAES-OAEP + MGF1-SHA256) * Derives an encryption key from the secret value and its RSA-encrypted ciphertext, using HMAC-SHA256. * Encrypts your plaintext message using defuse/php-encryption (authenticated symmetric-key encryption) * Calculates a checksum of both encrypted values (and a version tag)
  • Authentication * Signs a message using PHPSecLib (RSASS-PSS + MGF1-SHA256)

Support Contracts

If your company uses this library in their products or services, you may be interested in purchasing a support contract from Paragon Initiative Enterprises.


  Files folder image Files  
File Role Description
Files folder imagesrc (6 files, 1 directory)
Files folder imagetest (3 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.sh Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me
Accessible without login Plain text file SECURITY.md Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageException (3 files)
  Accessible without login Plain text file EasyRSA.php Class Class source
  Accessible without login Plain text file EasyRSAInterface.php Class Class source
  Accessible without login Plain text file KeyPair.php Class Class source
  Accessible without login Plain text file Kludge.php Class Class source
  Accessible without login Plain text file PrivateKey.php Class Class source
  Accessible without login Plain text file PublicKey.php Class Class source

  Files folder image Files  /  src  /  Exception  
File Role Description
  Accessible without login Plain text file InvalidChecksumException.php Class Class source
  Accessible without login Plain text file InvalidCiphertextException.php Class Class source
  Accessible without login Plain text file InvalidKeyException.php Class Class source

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file EncryptionTest.php Class Class source
  Accessible without login Plain text file KeyPairTest.php Class Class source
  Accessible without login Plain text file SignatureTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:51
This week:0
All time:10,653
This week:455Up