2017 © Pedro Peláez
 

library crypt

Webiny Crypt Component

image

webiny/crypt

Webiny Crypt Component

  • Friday, September 29, 2017
  • by SvenAlHamad
  • Repository
  • 5 Watchers
  • 1 Stars
  • 97 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 23 Versions
  • 28 % Grown

The README.md

Crypt Component

The Crypt component provides methods for generating random numbers and strings, also, password hashing and password hash verification and methods for encryption and decryption of strings. Internally it uses cryptographically secure methods., (*1)

Disclaimer: The library was not reviewed by a security expert., (*2)

Install the component

The best way to install the component is using Composer. This library requires that you also add a repository to your composer.json file., (*3)

composer require webiny/crypt

For additional versions of the package, visit the Packagist page., (*4)

Using Crypt

class MyClass
{
    use Webiny\Component\Crypt\CryptTrait;

    function myMethod()
    {
        $this->crypt()->encrypt('to encrypt', 'secret key');
    }
}

Generate random integers

To generate a random integer you just have to pass the range to the Crypt instance:, (*5)

    $randomInt = $crypt->generateRandomInt(10, 20); // e.g. 15

Generate random strings

When you want to generate random string, you have several options. You can call the general generateRandomString method, or you can call generateUserReadableString method to get a more user-readable string that doesn't contain any special characters. There is also a method called generateHardReadableString that, among letters and numbers, uses special characters to make the string more "harder". Here are a few examples:, (*6)

    // generate a string from a defined set of characters
    $randomString = $crypt->generateRandomString(5, 'abc'); // e.g. cabcc

    // generate a string that contains only letters (lower & upper case and numbers)
    $randomString = $crypt->generateUserReadableString(5); // A12uL

    // generate a string that can contain special characters
    $randomString = $crypt->generateHardReadableString(5); // &"!3g

Password hashing and validation

    // hash password
    $passwordHash = $crypt->createPasswordHash('login123'); // $2y$08$GgGha6bh53ofEPnBawShwO5FA3Q8ImvPXjJzh662/OAWkjeejAJKa

    // (on login page) verify the hash with the correct password
    $passwordsMatch = $crypt->verifyPasswordHash('login123', $passwordHash); // true or false

Encrypting and decrypting strings

    // encrypt it
    $encrypted = $crypt->encrypt('some data', 'abcdefgh12345678');

    // decrypt it
    $decrypted = $crypt->decrypt($result, 'abcdefgh12345678'); // "some data"

Crypt config

There are three different internal crypt libraries that you can choose from: 1. OpenSSL - this is the default library 2. Sodium - library that utilizes paragonie/halite internally for password hashing, password verification, encryption and decryption. Please note that this library is highly CPU intensive. 3. Mcrypt - this is the depricated library which will be removed once we hit PHP v7.2, (*7)

To switch between libraries, just set a different Bridge in your configuration:, (*8)

Crypt:
    Bridge: \Webiny\Component\Crypt\Bridge\Sodium\Crypt

and then in your code just call:, (*9)

\Webiny\Components\Crypt\Crypt::setConfig($pathToYourYaml);

Custom Crypt driver

To create a custom Crypt driver, first you need to create a class that implements \Webiny\Component\Crypt\Bridge\CryptInterface. Once you have implemented all the requested methods, you now need to change the Bridge path inside your component configuration., (*10)

Resources

To run unit tests, you need to use the following command:, (*11)

$ cd path/to/Webiny/Component/Crypt/
$ composer.phar install
$ phpunit

The Versions

29/09 2017

dev-master

9999999-dev http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

29/09 2017

1.6.x-dev

1.6.9999999.9999999-dev http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

29/09 2017

v1.6.0

1.6.0.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

29/09 2017

v1.6.1

1.6.1.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

08/09 2017

1.5.x-dev

1.5.9999999.9999999-dev http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

08/09 2017

v1.5.0

1.5.0.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

21/08 2016

1.4.x-dev

1.4.9999999.9999999-dev http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

21/08 2016

v1.4.3

1.4.3.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

04/02 2016

v1.4.0

1.4.0.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

04/02 2016

v1.4.1

1.4.1.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

04/02 2016

v1.4.2

1.4.2.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

16/03 2015

1.3.x-dev

1.3.9999999.9999999-dev http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

16/03 2015

v1.3.0

1.3.0.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

04/02 2015

1.2.x-dev

1.2.9999999.9999999-dev http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

04/02 2015

v1.2.0

1.2.0.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

04/02 2015

v1.2.1

1.2.1.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

04/02 2015

v1.2.2

1.2.2.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

04/02 2015

v1.2.3

1.2.3.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

28/11 2014

v1.1.1

1.1.1.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

23/11 2014

1.1.x-dev

1.1.9999999.9999999-dev http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

23/11 2014

v1.1.0

1.1.0.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

20/09 2014

1.0.x-dev

1.0.9999999.9999999-dev http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode

20/09 2014

v1.0.0

1.0.0.0 http://www.webiny.com/

Webiny Crypt Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

blowfish crypt hash encode decode