krmgns / cryptee
PHP 实现的简单、快速且安全的双向加密。
3.0.1
2024-01-26 02:44 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: >=9.0
README
对于 Cryptee/2.0,需要 PHP/7.4 或更高版本,但较旧的 Cryptee 版本(1.0、1.1、1.2)也可以与较旧的 PHP 版本一起使用。
您可以通过以下命令在控制台使用 Composer 安装它
composer require krmgns/cryptee
用法
use Cryptee\Cryptee; // Keep this key in save! $key = '4]%gmHo"e:]*hR(NQ?B...'; $str = 'Lorem ipsum dolor.'; $c = new Cryptee($key); // Or hex way. // $c = new Cryptee($key, Cryptee::HEX); $crypted = $c->crypt($str); $encoded = $c->encode($str); $decoded = $c->decode($encoded); printf("Crypted String: %s\n", $crypted); printf("Encoded String: %s\n", $encoded); printf("Decoded String: %s\n", $decoded); // Crypted String: X�/����;���-6�[�� // Encoded String: WJAv2/6x5Du/5IXjLTakW+jr // Decoded String: Lorem ipsum dolor.
使用不同密钥
// Keep these keys in save! const FOO_KEY = 'z:W;[*l>Eq.h"t)cs#XhU\+!=S]#q)\yG-...'; const BAR_KEY = 'SNz6@b*/k(iw!plOVeTBWxpL[1$;la|kb2...'; $cFoo = new Cryptee(FOO_KEY); $cBar = new Cryptee(BAR_KEY);
生成密钥
您可以通过调用 Cryptee::generateKey()
方法并带/不带 $length
参数(作为密钥长度)来生成新密钥。默认长度为 128。