码迷,mamicode.com
首页 > 其他好文 > 详细

tp5的rsa加密

时间:2020-06-27 16:04:16      阅读:116      评论:0      收藏:0      [点我收藏+]

标签: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;
}

}

tp5的rsa加密

标签:put   ase   key   you   ring   私钥   lib   return   php   

原文地址:https://www.cnblogs.com/-lsf/p/13198438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!