phpRSA加密解密函数
时间:2023年09月19日
/来源:网络
/编辑:佚名
使用方法:
加密
点击复制代码 PHP
$txt="78moban";
$pubkey="公钥"
$macdata = RSAEncrypt::encrypt($txt, $pubkey);
解密
点击复制代码 PHP
$txt="78moban";
$pubkey="私钥"
$macdata = RSAEncrypt::decrypt($txt, $pubkey);
类文件
点击复制代码 PHP
class RSAEncrypt {
public static function encrypt($str, $publicKey) {
$pubKey = openssl_pkey_get_public($publicKey);
openssl_public_encrypt($str, $outStr, $pubKey);
return base64_encode($outStr);
}
public static function decrypt($str, $privateKey) {
$inputByte = base64_decode($str);
$decoded = base64_decode($privateKey);
$priKey = openssl_pkey_get_private($decoded);
openssl_private_decrypt($inputByte, $outStr, $priKey);
return $outStr;
}
}
加密
点击复制代码 PHP
$txt="78moban";
$pubkey="公钥"
$macdata = RSAEncrypt::encrypt($txt, $pubkey);
解密
点击复制代码 PHP
$txt="78moban";
$pubkey="私钥"
$macdata = RSAEncrypt::decrypt($txt, $pubkey);
类文件
点击复制代码 PHP
class RSAEncrypt {
public static function encrypt($str, $publicKey) {
$pubKey = openssl_pkey_get_public($publicKey);
openssl_public_encrypt($str, $outStr, $pubKey);
return base64_encode($outStr);
}
public static function decrypt($str, $privateKey) {
$inputByte = base64_decode($str);
$decoded = base64_decode($privateKey);
$priKey = openssl_pkey_get_private($decoded);
openssl_private_decrypt($inputByte, $outStr, $priKey);
return $outStr;
}
}
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03