Giter Club home page Giter Club logo

phpcrypto's Introduction

PHPCrypto

Build Status

About

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

  • 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!

Usage

The usage is quite straightforward, after installing the library using composer:

composer require ezimuel/phpcrypto:dev-master

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

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

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:

TO DO

  • 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:

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

Copyright

Copyright 2016 by Enrico Zimuel

The license usage is reported in the LICENSE file.

phpcrypto's People

Contributors

ezimuel avatar paragonie-scott avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.