2017 © Pedro Peláez
 

library dcrypt

A petite library of encryption functionality for PHP

image

mmeyer2k/dcrypt

A petite library of encryption functionality for PHP

  • Friday, July 27, 2018
  • by mmeyer2k
  • Repository
  • 6 Watchers
  • 69 Stars
  • 15,554 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 34 Versions
  • 6 % Grown

The README.md

:closed_lock_with_key:dcrypt

Build Status Code Coverage Scrutinizer Code Quality Code Climate GPA License Latest Stable Version, (*1)

A petite library of essential encryption functions for PHP 7.1+. For legacy PHP version support, look here., (*2)

Install

Add dcrypt to your composer.json file requirements. Don't worry, dcrypt does not have any dependencies of its own., (*3)

composer require "mmeyer2k/dcrypt:^13.2"

Block Ciphers

The dcrypt library helps application developers avoid common mistakes in crypto implementations that leave data at risk., (*4)

Specification document, (*5)

Keys

Safe usage of dcrypt's block cipher functions requires the use of a high entropy 256 bit (minimum) key. Keys should be passed into dcrypt in base64 encoded format. You are responsible for the randomness of your key!, (*6)

Generate a new key on the linux CLI:, (*7)

head -c 32 /dev/urandom | base64 -w 0 | xargs echo

Or with PHP..., (*8)

<?php
$key = \Dcrypt\OpensslKey::create(32);

AES-256 GCM Encryption

Since PHP 7.1 supports native AEAD encryption modes, using GCM would be safest option for most applications. Dcrypt will handle the AEAD authentication tag, SHA3-256 HMAC, initialization vector and encrypted message as a single unencoded string., (*9)

<?php
$key = '[...BASE64 KEY...]';

$encrypted = \Dcrypt\Aes::encrypt('a secret', $key);

$plaintext = \Dcrypt\Aes::decrypt($encrypted, $key);

If in doubt, use this example and don't read any further!, (*10)

Other AES-256 Modes

If you read to this point then you are an experienced cryptonaut, congrats! :ok_hand: :metal:, (*11)

Several AES-256 encryption modes are supported out of the box via hardcoded classes., (*12)

Class Name OpenSSL Cipher Security Rating Further Reading
Aes256Gcm or Aes aes-256-gcm :smiley: wiki
Aes256Ctr aes-256-ctr :relaxed: wiki
Aes256Cbc aes-256-cbc :expressionless: wiki
Aes256Ofb aes-256-ofb :grimacing: wiki
Aes256Cfb aes-256-cfb :hushed: wiki
Aes256Ccm aes-256-ccm :astonished: wiki
Aes256Ecb aes-256-ecb :rage: wiki

Custom Encryption Suites

Dcrypt is compatible with most OpenSSL ciphers and hashing algorithms supported by PHP. Run openssl_get_cipher_methods() and hash_algos() to view supported options on your platform., (*13)

Static Wrapper

Use any cipher/algo combination by calling the OpensslStatic class., (*14)

<?php
$encrypted = \Dcrypt\OpensslStatic::encrypt('a secret', $key, 'bf-ofb', 'crc32');

$plaintext = \Dcrypt\OpensslStatic::decrypt($encrypted, $key, 'bf-ofb', 'crc32');

Class Overloading

Dcrypt's internal functions are easily extendable by overloading the OpensslBridge class., (*15)

<?php
class BlowfishCrc32 extends \Dcrypt\OpensslBridge 
{
    const CIPHER = 'bf-ofb';

    const ALGO = 'crc32';
}

$encrypted = BlowfishCrc32::encrypt('a secret', $key);

$plaintext = BlowfishCrc32::decrypt($encrypted, $key);

Layered Encryption Factory

Feeling especially paranoid? Not sure which cipher methods and algos can be trusted? Why not try all of them., (*16)

<?php
$stack = (new \Dcrypt\OpensslStack($key))
    ->add('aes-256-ecb', 'snefru')
    ->add('aes-256-ofb', 'sha224')
    ->add('aes-256-cbc', 'sha256')
    ->add('aes-256-ctr', 'sha384')
    ->add('aes-256-gcm', 'sha512');

$encrypted = $stack->encrypt('a secret');

$plaintext = $stack->decrypt($encrypted);

Message Authenticity Checking

By default, \Dcrypt\Exceptions\InvalidChecksumException exception will be raised before decryption is allowed to proceed when the supplied checksum is not valid., (*17)

<?php
try {
    $decrypted = \Dcrypt\Aes::decrypt('malformed cyphertext', $key);
} catch (\Dcrypt\Exceptions\InvalidChecksumException $ex) {
    // ...
}

Stream Ciphers

Be sure you understand the risks and inherent issues of using a stream cipher before proceeding., (*18)

One Time Pad

A novel counter-based stream cipher. OneTimePad uses SHA3-512 to output a keystream that is ⊕'d with the input in 512 bit chunks., (*19)

Specification document, (*20)

<?php
$encrypted = \Dcrypt\OneTimePad::crypt('a secret', $key);

$plaintext = \Dcrypt\OneTimePad::crypt($encrypted, $key);

OneTimePad can use any hashing algorithm to generate the pseudorandom keystream., (*21)

<?php
$encrypted = \Dcrypt\OneTimePad::crypt('a secret', $key, 'whirlpool');

$plaintext = \Dcrypt\OneTimePad::crypt($encrypted, $key, 'whirlpool');

String Helpers

Generate random base62 string tokens with specified number of characters., (*22)

$token = \Dcrypt\Str::token(10);

Compare 2 strings in a time-safe manner., (*23)

$equal = \Dcrypt\Str::equal($known, $given);

Show me some love :heart_eyes::beer:

Developing dcrypt has been a great journey for many years. If you find dcrypt useful, please consider donating., (*24)

LTC LN97LrLCNiv14V6fntp247H2pj9UiFzUQZ
BTC 3N7vhA6ghWb1VrP4nGA6m6mzA9T2ASCVEj
ETH 0xe14a56046f28fCEF56A0EA4a84973bDdFF546923

Or please consider checking out my dcrypt inspired encryption library for .NET, check out harpocrates., (*25)

The Versions

27/07 2018

dev-master

9999999-dev

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

27/07 2018

8.3.1

8.3.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

14/07 2018

8.3.0

8.3.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

14/07 2018

dev-tinyfish

dev-tinyfish

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

12/07 2018

8.2.1

8.2.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

12/07 2018

8.2.0

8.2.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

02/03 2018

8.1.0

8.1.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

23/02 2018

8.0.1

8.0.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

23/02 2018

8.0.0

8.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

23/02 2018

7.0.1

7.0.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

13/02 2018

7.0.0

7.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

09/02 2018

6.0.3

6.0.3.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

07/02 2018

6.0.2

6.0.2.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

26/01 2018

6.0.1

6.0.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

26/01 2018

6.0.0

6.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

24/01 2018

dev-otp

dev-otp

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

23/01 2018

5.0.0

5.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

22/01 2018

dev-php7

dev-php7

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

20/12 2017

4.0.2

4.0.2.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

16/12 2017

4.0.1

4.0.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

13/12 2017

4.0.0

4.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

26/11 2017

3.1.0

3.1.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

14/09 2017

dev-huffman

dev-huffman

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

21/08 2017

3.0.1

3.0.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

24/05 2016

3.0.0

3.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

03/03 2016

2.0.1

2.0.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

22/02 2016

2.0.0

2.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

22/02 2016

1.0.1

1.0.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

20/02 2016

1.0.0

1.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

08/01 2016

0.1.0

0.1.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

02/10 2015

0.0.3

0.0.3.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

encryption otp aes openssl hashing mcrypt rc4 pbkdf pkcs7 spritz

25/07 2015

0.0.2

0.0.2.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

01/07 2015

0.0.1

0.0.1.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer

30/06 2015

0.0.0

0.0.0.0

A petite library of encryption functionality for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michael Meyer