l-freeze / crypto
本包提供了一些加密方法的加密功能。
v0.1.0
2023-10-08 04:38 UTC
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2024-09-08 07:41:37 UTC
README
为什么?
-
当指定iv时,加密结果将始终相同。但是,不指定iv的方法安全性更高
-
支持sodium/openssl
-
由于可以使用sodium/openssl中的任何一个库,因此不需要在required中指定它们
用法
安装
composer require l-freeze/crypto
或者
docker run --rm --interactive --tty --volume $PWD:/app --user $(id -u):$(id -g) composer require l-freeze/crypto
示例
//index.php <?php declare(strict_types=1); require('vendor/autoload.php'); use LFreeze\Crypto\Crypto; //Encryption by Sodium Crypto::setcryptoMethod(Crypto::METHOD_SODIUM); $key ='EncryptionKey#MustStringLength32'; $iv = 'InitializationVector::24'; $resource = <<<EOT ========================= [SODIUM: Specified iv -> FixedEncryptedString] ========================= EOT; $encrypted = Crypto::encrypt($resource, $key, $iv); print_r($encrypted); $decrypted = Crypto::decrypt($encrypted, $key, $iv); print_r($decrypted);
php index.php
或者
docker run --rm -u "$(id -u):$(id -g)" -it --tty -w /home -v ${PWD}:/home php:8.2-cli php index.php
其他
https://github.com/l-freeze/php-crypto/blob/master/example.php