标签:put ase key you ring 私钥 lib return php
<?php
/**
* Description of Rsa
*
* @author lsf
*/
namespace lib;
class Rsa {
//put your code here
static public $private_parm = null;
static public $public_parm = null;
static public $private_key = null;
static public $public_key = null;
/**
* 构造函数
*/
public function __construct() {
self::$private_parm = config("web.private_parm");
self::$public_parm = config("web.public_parm");
self::$private_key = openssl_pkey_get_private(self::$private_parm);
self::$public_key = openssl_pkey_get_public(self::$public_parm);
}
/**
* 私钥加密
* @param type $data 需要加密额字符串长度小于100
* @return type
*/
static public function privateRncrypt($data) {
$encrypted = "";
$rsa = new Rsa();
openssl_private_encrypt($data, $encrypted, $rsa::$private_key);
return base64_encode($encrypted);
}
/**
* 公钥解密
* @param type $endata 加密后的字符串
* @return string
*/
static public function publicDecrypt($endata) {
$decrypted = "";
$rsa = new Rsa();
openssl_public_decrypt(base64_decode($endata), $decrypted, $rsa::$public_key);
return $decrypted;
}
/**
* 公钥加密
* @param type $data 需要加密额字符串长度小于100
* @return string
*/
static public function publicRncrypt($data) {
$encrypted = "";
$rsa = new Rsa();
openssl_public_encrypt($data, $encrypted, $rsa::$public_key);
return base64_encode($encrypted);
}
/**
* 私钥解密
* @param type $endata 加密后的字符串
* @return string
*/
static public function privateDecrypt($endata) {
$decrypted = "";
$rsa = new Rsa();
openssl_private_decrypt(base64_decode($endata), $decrypted, $rsa::$private_key);
return $decrypted;
}
}
标签:put ase key you ring 私钥 lib return php
原文地址:https://www.cnblogs.com/-lsf/p/13198438.html