2017 © Pedro Peláez
 

library phpcrypto

Cryptographic library for PHP 7 based on OpenSSL

image

ezimuel/phpcrypto

Cryptographic library for PHP 7 based on OpenSSL

  • Friday, April 8, 2016
  • by ezimuel
  • Repository
  • 2 Watchers
  • 14 Stars
  • 777 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 9 % Grown

The README.md

PHPCrypto

Build Status, (*1)

About

This is a cryptography library for PHP 7. It's based on OpenSSL and provides the following features:, (*2)

  • Symmetric encryption and authentication (AES + HMAC-SHA256 as default);
  • Public Key cryptography (management keys, encryption/decryption)
  • Hybrid encryption using symmetric and public key (OpenPGP like)

Version

As this software is ALPHA, Use at your own risk!, (*3)

Usage

The usage is quite straightforward, after installing the library using composer:, (*4)

composer require ezimuel/phpcrypto:dev-master

You can consume the following classes Symmetric, PublicKey and Hybrid for symmetric encryption, public key and hybrid encryption., (*5)

For instance, if you want to encrypt a string in a symmetric way, you can use the following code:, (*6)

use PHPCrypto\Symmetric;

$plaintext = 'Text to encrypt';
$key = '123456789012'; // This can be also a user's password we generate a new
                       // one for encryption using PBKDF2 algorithm

$cipher = new Symmetric(); // AES + HMAC-SHA256 by default
$cipher->setKey($key);
$ciphertext = $cipher->encrypt($plaintext);

// or passing the $key as optional paramter
// $ciphertext = $cipher->encrypt($plaintext, $key);

$result = $cipher->decrypt($ciphertext);

// or passing the $key as optional paramter
// $result = $cipher->decrypt($ciphertext, $key);

print ($result === $plaintext) ? "OK" : "FAILURE";

SECURITY BEST PRACTICES

In this project we used the following security best practices:, (*7)

TO DO

  • [x] encrypt/decrypt functions in PublicKey
  • [ ] sign/verify functions for digital signature in PublicKey
  • [ ] support multiple keys in Hybrid schema
  • [ ] Ca management in public key schemas

NOTES ABOUT OPENSSL EXTENSION

Here I reported some notes about the OpenSSL PHP extension usage:, (*16)

  • it will be nice to have the openssl_cipher_key_size() function to get the key size of the specific cipher choosen;

Copyright 2016 by Enrico Zimuel, (*17)

The license usage is reported in the LICENSE file., (*18)

The Versions

08/04 2016

dev-master

9999999-dev https://github.com/ezimuel/phpcrypto

Cryptographic library for PHP 7 based on OpenSSL

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-openssl *

 

The Development Requires

cryptography php7