laswitchtech / php-encryption
PHP 加密类
v2.0.1
2023-01-06 20:37 UTC
Requires
- php: ^8.0
README
phpEncryption - [已弃用] - 请使用 coreEncryption 代替
特性
- openSSL 加密
你可能需要它的原因
如果你在寻找一种简单的方式来开始使用加密。这个 PHP 类就是为你准备的。
我能使用这个吗?
当然可以!
许可证
本软件在 GNU 通用公共许可证 v3.0 许可下分发。请阅读 LICENSE 了解软件可用性和分发信息。
要求
PHP >= 5.6.0
安全性
请负责任地披露发现的任何漏洞 - 私下向维护者报告安全问题。
安装
使用 Composer
composer require laswitchtech/php-encryption
我如何使用它?
示例
初始化
//Import phpEncryption class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpEncryption\phpEncryption; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate Class Encryption $phpEncryption = new phpEncryption();
设置自己的私钥
//Import phpEncryption class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpEncryption\phpEncryption; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate Class Encryption $phpEncryption = new phpEncryption(); //Set Initial Value $PrivateKey = $phpEncryption->setPrivateKey("My Private Key"); //Output Initial Value echo json_encode($PrivateKey, JSON_PRETTY_PRINT) . PHP_EOL;
设置自己的公钥
//Import phpEncryption class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpEncryption\phpEncryption; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate Class Encryption $phpEncryption = new phpEncryption(); //Set Secret Value $PublicKey = $phpEncryption->setPublicKey("My Public Key"); //Output Initial Value echo json_encode($PublicKey, JSON_PRETTY_PRINT) . PHP_EOL;
加密数据
//Import phpEncryption class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpEncryption\phpEncryption; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate Class Encryption $phpEncryption = new phpEncryption(); //Encrypt Data $Data = $phpEncryption->encrypt("Hello Wolrd!"); //Output Encrypted Data echo json_encode($Data, JSON_PRETTY_PRINT) . PHP_EOL;
解密数据
//Import phpEncryption class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpEncryption\phpEncryption; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate Class Encryption $phpEncryption = new phpEncryption(); //Decrypt Data $Data = $phpEncryption->decrypt($Data); //Output Decrypted Data echo json_encode($Data, JSON_PRETTY_PRINT) . PHP_EOL;
加密文件
//Import phpEncryption class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpEncryption\phpEncryption; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate Class Encryption $phpEncryption = new phpEncryption(); //Encrypt File $File = $phpEncryption->encrypt('decrypted.txt', 'encrypted.txt'); //Output Encrypted File echo json_encode($File, JSON_PRETTY_PRINT) . PHP_EOL;
解密文件
//Import phpEncryption class into the global namespace //These must be at the top of your script, not inside a function use LaswitchTech\phpEncryption\phpEncryption; //Load Composer's autoloader require 'vendor/autoload.php'; //Initiate Class Encryption $phpEncryption = new phpEncryption(); //Decrypt File $File = $phpEncryption->decrypt('encrypted.txt', 'decrypted.txt'); //Output Decrypted File echo json_encode($File, JSON_PRETTY_PRINT) . PHP_EOL;