PHP code example of lfyw / opencrypt
1. Go to this page and download the library: Download lfyw/opencrypt library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lfyw / opencrypt example snippets
/**
* Filename:openssl.php
* Author:ld
* Date:2021/8/18
*/
return [
/** 是否开启加解密 **/
'opencrypt' => env('OPENCRYPT', false),
/** 密钥保存方式 file => 文件保存模式 'env' => 环境变量保存方式 **/
'opencrypt_type' => env('OPENCRYPT_TYPE', 'file'),
/** 仅文件保存模式时需要设置以下配置项 **/
/** 文件保存模式-密钥地址 **/
'opencrypt_path' => env('OPENCRYPT_PATH', resource_path('opencrypt')),
/** 文件保存模式-私钥文件名称 **/
'opencrypt_private_key_filename' => env('OPENCRYPT_PRIVATE_KEY_FILENAME', 'private_key.pem'),
/** 文件保存模式-公钥文件名称**/
'opencrypt_public_key_filename' => env('OPENCRYPT_PUBLIC_KEY_FILENAME', 'public_key.pem'),
/** 以下配置项仅环境变量模式时有效 **/
/** 公钥 **/
'opencrypt_public_key' => env('OPENCRYPT_PUBLIC_KEY'),
/** 私钥 **/
'opencrypt_private_key' => env('OPENCRYPT_PRIVATE_KEY'),
];
/** 加密 **/
app('opencrypt')->encrypt('123');//返回加密字符串
/** 解密 **/
app('opencrypt')->decrypt('123');//返回解密字符串,无法解密会返回null
/** 判断字符串加密后是否等于密文参数 **/
app('opencrypt')->equal('密文','123');//返回布尔值
/** 获取公钥 **/
app('opencrypt')->getPrivateKey();
/** 获取私钥 **/
app('opencrypt')->getPublicKey();
/** 加密 **/
openencrypt('123');//返回加密字符串
/** 解密 **/
opendecrypt('123');//返回解密字符串,无法解密会返回null
shell
$ php artisan vendor:publish --provider="Lfyw\Opencrypt\ServiceProvider"
shell
$ php artisan opencrypt:generate
php
** 加密 **/
Opencrypt::encrypt('123');//返回加密字符串
/** 解密 **/
Opencrypt::decrypt('123');//返回解密字符串,无法解密会返回null
/** 判断字符串加密后是否等于密文参数 **/
Opencrypt::equal('密文','123');//返回布尔值
/** 获取公钥 **/
Opencrypt::getPrivateKey();
/** 获取私钥 **/
Opencrypt::getPublicKey();