PHPackages                             grandmasterx/encryptdectypt - 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. grandmasterx/encryptdectypt

ActiveLibrary[Security](/categories/security)

grandmasterx/encryptdectypt
===========================

Encrypt-dectypt API

01.8kPHP

Since Mar 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/GrandMasterX/encryptdectypt)[ Packagist](https://packagist.org/packages/grandmasterx/encryptdectypt)[ RSS](/packages/grandmasterx-encryptdectypt/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Windwalker Crypt
================

[](#windwalker-crypt)

Windwalker Crypt package is a wrap of PHP Openssl and Libsodium library to hash and verify password, and provides an easy interface to do Symmetric Algorithm encryption.

Installation via Composer
-------------------------

[](#installation-via-composer)

Add this to the require block in your `composer.json`.

```
{
    "require": {
        "windwalker/crypt": "~3.0"
    }
}
```

Password Hashing
----------------

[](#password-hashing)

`Password` object is a simple object to encrypt user's password, it is impossible to decrypt password hash, `Password` object uses a one-way algorithm.

### Create Password

[](#create-password)

```
use Windwalker\Crypt\Password;

$password = new Password;

$pass = $password->create('pass1234');

// $2y$10$csNfML/FJlKwaHR8xREgZuhp0pqSqeg.jdACqDsKO/MCHDkTuIZEa
```

Using other hash algorithm

```
use Windwalker\Crypt\Password;

$password = new Password(Password::SHA256);

$pass = $password->create('pass1234');
```

Set cost and salt:

```
use Windwalker\Crypt\Password;

// The Blowfish algorithm should set cost number between 4 to 31.
// We are suggest not higher than 15, else it will be too slow.
$password = new Password(Password::BLOWFISH, 15, md5('to be or not to be.'));

$pass = $password->create('pass1234');

// Note the Sha256 and Sha512 should set cost number higher than 1000
$password = new Password(Password::SHA512, 5000, md5('to be or not to be.'));

$pass = $password->create('pass1234');
```

### Available algorithms

[](#available-algorithms)

- Password::MD5
- Password::BLOWFISH (default)
- Password::SHA256
- Password::SHA512
- Password::ARGON2 (libsodium)
- Password::SCRYPT (libsodium)

> NOTE: `ARGON2` and `SCRYPT` must install php `ext-libsodium` and libsodium library first. Native PHP cannot implement them. These 2 algos will ignore cost and salt and use Sodium way to hash password.

### Verify Password

[](#verify-password)

We don't need to care the hash algorithm, Password object will auto detect the algorithm type:

```
$bool = $password->verify('pass1234', $pass);
```

Symmetric-Key Algorithm Encryption
----------------------------------

[](#symmetric-key-algorithm-encryption)

The `Crypt` object provides different ciphers to encrypt/decrypt your data. Most of these ciphers must use PHP openssl functions to work. If your PHP are not available for openssl extension, you can use `PhpAesCipher`as default cipher, it is a native PHP implementation of AES by [aes.class.php](https://gist.github.com/chrisns/3992815).

### Use Cipher

[](#use-cipher)

```
use Windwalker\Crypt\Cipher\BlowfishCipher;
use Windwalker\Crypt\Crypt;

$crypt = new Crypt(new BlowfishCipher);

$encrypted = $crypt->encrypt('My Text', 'My private key');

$bool = $crypt->verify('My Text', $encrypted, 'My private key'); // True
```

Get the plain text back:

```
$crypt = new Crypt(new BlowfishCipher);

$encrypted = $crypt->encrypt('My Text', 'My private key');

$text = $crypt->decrypt($encrypted);
```

### Custom Cipher

[](#custom-cipher)

You can set mode to cipher.

```
$cipher = new BlowfishCipher($key);

$cipher->setMode('ecb');

$cipher->encrypt(...);
```

Or set the PBKDF2 iteration count.

```
$cipher = new BlowfishCipher($key, array('pbkdf2_iteration' => 64000)); // Default is 12000
```

### Libsodium

[](#libsodium)

Use [Libsodium](https://github.com/jedisct1/libsodium) to encrypt data, you must install [paragonie/sodium\_compat](https://github.com/paragonie/sodium_compat) first.

`paragonie/sodium_compat` helps us use libsodium without extension, but you should install `ext-libsodium` to get higher performance.

```
use Windwalker\Crypt\Cipher\SodiumCipher;

$crypt = new Crypt(new SodiumCipher);

$encrypted = $cipher->encrypt($text);

$text = $cipher->decrypt($encrypted);
```

Pure php cannot implement memory wipe, if you get `sodium_memzero() only supports after php 7.2 or ext-libsodium installed.` message, it means you must install `ext-libsodium` or use php 7.2 or higher, you can also disable memory wipe by `ignoreMemzero()` (But we don't recommend to do this):

```
$cipher = new SodiumCipher;
$cipher->ignoreMemzero(true);

$crypt = new Crypt($cipher);
```

### Available Ciphers

[](#available-ciphers)

- [BlowfishCipher](http://en.wikipedia.org/wiki/Blowfish_(cipher))
- [Aes56Cipher](http://en.wikipedia.org/wiki/Advanced_Encryption_Standard)
- [Des3Cipher](http://en.wikipedia.org/wiki/Triple_DES)
- [SodiumCipher](https://paragonie.com/book/pecl-libsodium/read/00-intro.md) - PHP Libsodium cipher, must install `ext-libsodium` first.
- PhpAesCipher - Only use this when system not support openssl extension.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/da448c29b0b269957ab1b48b4e90ee34100f676f17645320ccf7fccd5c3c55f9?d=identicon)[GrandMasterX](/maintainers/GrandMasterX)

### Embed Badge

![Health badge](/badges/grandmasterx-encryptdectypt/health.svg)

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

###  Alternatives

[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k18.0M138](/packages/mews-purifier)[paragonie/ecc

PHP Elliptic Curve Cryptography library

24772.0k35](/packages/paragonie-ecc)

PHPackages © 2026

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