jf / crypto
1.0.0
2024-03-02 18:18 UTC
Suggests
- jf/base: Para cifrar identificadores de entidades o recursos
README
文本和文件的加密和解密。
安装
Composer
本项目使用 Composer 作为依赖管理器,可以按照项目官方文档中的说明进行安装(文档)。
要使用此包管理器安装 jf/crypto
包,需要执行
composer require jf/crypto
版本控制
本项目可以使用 git
安装。首先需要克隆项目,然后安装依赖项
git clone git@gitlab.com:joaquinfq/jfCrypto.git
cd jfCrypto
composer install
可用文件
类
名称 | 描述 |
---|---|
jf\Crypto\ACipher | 用于简单加密数据库或配置文件的类。 |
jf\Crypto\Assert | 由包抛出的异常。 |
jf\Crypto\AsymmetricKeys | 管理使用非对称密钥的加密和解密需求。 |
jf\Crypto\Cipher | 用于简单加密文本或数据的类。 |
jf\Crypto\FileCipher | 用于简单加密数据库或配置文件的类。 |
接口
名称 | 描述 |
---|---|
jf\Crypto\IAsymmetricKeys | 管理非对称加密密钥的类的接口。 |
jf\Crypto\ICipher | 用于加密/解密文本的接口。 |
jf\Crypto\ICrypto | 管理加密密钥的类的接口。 |
jf\Crypto\ICryptoId | 需要加密其标识符的类的接口。 |
jf\Crypto\IFileCipher | 用于加密/解密文件的接口。 |
特性
名称 | 描述 |
---|---|
jf\Crypto\TId | 用于应用到需要加密其数字标识符的对象的特性行为。 |
示例
jf\Crypto\AssymetricKeys
// Si no tenemos las claves las creamos
// AsymmetricKeys::createKeys(__DIR__);
// Al crear la clase especificamos el directorio donde se encuentran las claves.
$ecdsa = new AsymmetricKeys(__DIR__);
$content = file_get_contents(__FILE__);
$encrypted = $ecdsa->encrypt($content);
assert($ecdsa->decrypt($encrypted) === $content);
jf\Crypto\FileCipher
$content = file_get_contents(__FILE__);
$key = md5($content); // Asignamos la clave que queremos usar.
$cipher = new Cipher($key);
$filecipher = new FileCipher($key);
$encrypted = $cipher->encrypt($content);
$encfile = __FILE__ . '.encrypted';
assert($cipher->decrypt($encrypted) === $content);
assert($filecipher->save($encfile, $content) === strlen($encrypted));
assert($filecipher->load($encfile) === $content);
unlink($encfile);