PHPackages                             webiny/crypt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. webiny/crypt

ActiveLibrary[Security](/categories/security)

webiny/crypt
============

Webiny Crypt Component

v1.6.1(8y ago)22.6k↓100%31MITPHPPHP &gt;=7

Since Sep 20Pushed 8y ago11 watchersCompare

[ Source](https://github.com/Webiny/Crypt)[ Packagist](https://packagist.org/packages/webiny/crypt)[ Docs](http://www.webiny.com/)[ RSS](/packages/webiny-crypt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (23)Used By (1)

Crypt Component
===============

[](#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.

**Disclaimer:**The library was not reviewed by a security expert.

Install the component
---------------------

[](#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.

```
composer require webiny/crypt
```

For additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/crypt).

Using Crypt
-----------

[](#using-crypt)

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

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

Generate random integers
------------------------

[](#generate-random-integers)

To generate a random integer you just have to pass the range to the `Crypt` instance:

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

Generate random strings
-----------------------

[](#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:

```
    // 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
-------------------------------

[](#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
---------------------------------

[](#encrypting-and-decrypting-strings)

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

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

Crypt config
------------

[](#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](https://github.com/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

To switch between libraries, just set a different `Bridge` in your configuration:

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

and then in your code just call:

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

Custom `Crypt` driver
---------------------

[](#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.

Resources
---------

[](#resources)

To run unit tests, you need to use the following command:

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

```

###  Health Score

36

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~52 days

Recently: every ~5 days

Total

22

Last Release

3144d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v1.2.1PHP &gt;=5.5.9

v1.5.0PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4440afa738ed146b05c06073a90345e0464c4f4d042b039532d881ca24859d77?d=identicon)[SvenAlHamad](/maintainers/SvenAlHamad)

---

Top Contributors

[![SvenAlHamad](https://avatars.githubusercontent.com/u/3808420?v=4)](https://github.com/SvenAlHamad "SvenAlHamad (57 commits)")

---

Tags

blowfishhashencodedecodecrypt

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webiny-crypt/health.svg)

```
[![Health](https://phpackages.com/badges/webiny-crypt/health.svg)](https://phpackages.com/packages/webiny-crypt)
```

###  Alternatives

[hashids/hashids

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

5.5k48.6M275](/packages/hashids-hashids)[passwordlib/passwordlib

A Password Hashing Library

377220.6k6](/packages/passwordlib-passwordlib)[bordoni/phpass

Portable PHP password hashing framework

244.4M25](/packages/bordoni-phpass)[torann/hashids

Laravel package for Hashids

54335.1k](/packages/torann-hashids)[miladrahimi/phpcrypt

Encryption, decryption, and hashing tools for PHP projects

3171.5k2](/packages/miladrahimi-phpcrypt)[pentagonal/phpass

PHP password hashing library original by open wall PhPass

121.6k](/packages/pentagonal-phpass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
