PHP code example of job520 / encryption

1. Go to this page and download the library: Download job520/encryption 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/ */

    

job520 / encryption example snippets



// 1. 引入包
间
use job520\mcrypt;
use job520\openssl;
use job520\rsa;
// 3. 定义密钥
$key = 'abcdefg';
// 4. 原始数据
$data = '你好 world';
// 5. 实例化 mcrypt 加密类
$obj = new mcrypt($key);
// 6. 实例化 openssl 加密类
$obj = new openssl($key);
// 7. aes 加密
$encode = $obj->encrypt($data);
echo $encode . PHP_EOL;
// 8. aes 解密
$decode = $obj->decrypt($encode);
echo $decode . PHP_EOL;
// 9. 私钥路径
$private_key = 'rsa_private_key.pem';
// 10. 公钥路径
$public_key = 'rsa_public_key.pem';
// 11. 实例化 rsa 加密解密类
$rsa = new rsa($private_key, $public_key);
// 12. 测试数据
$origin_data = '这是一条测试数据';
// 13. rsa 公钥加密
$encrypt = $rsa->publicEncrypt($origin_data);
echo '公钥加密后的数据为:' . $encrypt . PHP_EOL;
// 14. rsa 私钥解密
$decrypt = $rsa->privDecrypt($encrypt);
echo '私钥解密后的数据为: ' . $decrypt . PHP_EOL;