PHPackages                             crazy/crypto - 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. crazy/crypto

ActiveLibrary[Security](/categories/security)

crazy/crypto
============

Unified management of common encryption and decryption class

1.2.0(6y ago)131MITPHPPHP &gt;=5.6.0

Since Mar 21Pushed 6y agoCompare

[ Source](https://github.com/crazys1973/crypto)[ Packagist](https://packagist.org/packages/crazy/crypto)[ RSS](/packages/crazy-crypto/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Crazy/crypto
============

[](#crazycrypto)

[![PHP Version](https://camo.githubusercontent.com/132eb2fad8bc173f1489c3481e81763d1a02b392a4e55bd35eb0a1fc8b5d1ee5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344352e362d3838393242462e737667)](http://www.php.net/)[![Latest Stable Version](https://camo.githubusercontent.com/9f206c0101aa2fccfe1e289d0f661c5ed8239240d9827b6fed19bc1f3123ae34/68747470733a2f2f706f7365722e707567782e6f72672f6372617a792f63727970746f2f762f737461626c65)](https://packagist.org/packages/crazy/crypto)[![License](https://camo.githubusercontent.com/00f597e4bf9fab8a5e5ae7731928f90410be18168eb2646cd7525fd6e1c04f0c/68747470733a2f2f706f7365722e707567782e6f72672f6372617a792f63727970746f2f6c6963656e7365)](https://packagist.org/packages/crazy/crypto)[![Total Downloads](https://camo.githubusercontent.com/6a302110809fc39abde88912ce27f4ca68893d8bc96598e0c89e0483af63b187/68747470733a2f2f706f7365722e707567782e6f72672f6372617a792f63727970746f2f646f776e6c6f616473)](https://packagist.org/packages/crazy/crypto)

简介
--

[](#简介)

由于PHP开发过程中，经常需要对信息进行可逆加解密，本人将ThinkPHP 3.x中的加解密类进行了重新封装，统一处理。本版中支持6种算法：`AES`、`Base64`、`Crypt`、`Des`、`Think`和`Xxtea`。

---

安装
--

[](#安装)

### Git

[](#git)

地址：`https://github.com/crazys1973/crypto.git`

### 码云

[](#码云)

地址：`https://gitee.com/crazys1973/crypto.git`

### Composer

[](#composer)

命令：`composer require crazy/crypto`

### 系统需求

[](#系统需求)

PHP版本5.6以上

---

使用方法
----

[](#使用方法)

#### 加密

[](#加密)

```
Crypto::{加密算法}()->encrypt(string $data, string $key[, int $expire = 0]);

```

返回：加密过后的字符串。

- {加密算法}：加密算法类的名称，目前支持 6 种，分别是：`AES`、`Base64`、`Crypt`、`Des`、`Think`和`Xxtea`。算法名大小写不敏感，Base64与bAsE64效果相同。如果算法名写错，则默认使用Think算法。
- $data：需要加密的字符串。
- $key：加密key，参与加密运算的字符串。
- $expire：有效期，单位为秒

例：

```
// 使用Base64算法加密
$encryptString = Crypto::Base64()->encrypt('Hello world!', 'key123');

// 使用ThinkPHP算法加密
$encryptString = Crypto::Think()->encrypt('Hello world!', 'key123');
```

#### 解密

[](#解密)

```
Crypto::{加密算法}()->decrypt(string $data, string $key);
```

返回：解密成功时返回解密字符串。解密失败或加密串过期，返回空字符串`''`。如果算法名写错，则默认使用Think算法。

- {加密算法}：与加密时的算法名必须相同。
- $data：需要解密的字符串。
- $key：加密时使用的加密key。

例：

```
// 使用Think算法解密
$data = 'sXym2IR3c62yeqbagn6ZosOq29p_rZTZnNGqoX20c3A';
echo Crypto::Base64()->decrypt($data, 'key123');

// 输出：Hello World!
```

---

\##版本更新

#### 1.2.0

[](#120)

- 新增AES加密算法。
- 修改所有数组为短语法。

#### 1.1.1

[](#111)

- 修复加密算法法不存在时报错，更改默认为Think加密方法，例：`Crypto::abc();`将会使用Think加解密算法。
- 添加类注释，方便IDE工具提示。

#### 1.1.0

[](#110)

- 新增Crypto类，集中统一管理加密类
- 新增Cryptoable接口
- 去除加密类的静态方法
- 类使用单例模式

#### 1.0.0

[](#100)

- 集成5种加密算法：Base64, Crypt, Des, Think, Xxtea。
- 修改源码中变量未初始化的bug。
- 更新代码注释。

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~140 days

Total

2

Last Release

2471d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9db0f560afa80d4004f5ce5417110745b13ab325334080ea026eadf7a789789e?d=identicon)[crazys1973](/maintainers/crazys1973)

---

Top Contributors

[![crazys1973](https://avatars.githubusercontent.com/u/23290527?v=4)](https://github.com/crazys1973 "crazys1973 (6 commits)")

### Embed Badge

![Health badge](/badges/crazy-crypto/health.svg)

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

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

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

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