php技术
当前位置:首页 > 商学院 > php技术 > 正文内容

php技术

phpRSA加密解密函数

豫唐网络2023-03-01 08:25111

使用方法:

加密

 $txt="ytecn";
 $pubkey="公钥"
 $macdata = RSAEncrypt::encrypt($txt, $pubkey);

解密

 $txt="ytecn";
 $pubkey="私钥"
 $macdata = RSAEncrypt::decrypt($txt, $pubkey);

类文件

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;
    }
}


扫描二维码推送至手机访问。

版权声明:本文由汤阴县豫唐网络科技有限公司发布,如需转载请注明出处。

本文链接:https://www.ytecn.com/post/552.html

分享给朋友:

相关文章

php将编码转换为UTF8

php将编码转换为UTF8

主要用于编码不统一导致出现乱码的情况,此函数会自动监测非UTF8编码转成UTF8编码。function ConverCode($str){ $encode = mb_d...

php获取网站在服务器中用的环境

php获取网站在服务器中用的环境

判断当前网站在服务器用的什么环境function GetWebServer() {     if (!isset($_SERVER[&#...

php分割string并取某项数据

php分割string并取某项数据

对string进行分割,并取某项数据。应用案例$txt="姓名|电话|手机号|豫唐"; $name=SplitAndGet($txt,"|",3); ech...

php删除连续空格

php删除连续空格

对字段中的连续空格进行删除只保留一个。应用案例$txt="     a b c   &nb...

php获取当前目录下文件夹列表

php获取当前目录下文件夹列表

获取当前目录下文件夹的名称应用案例$url="D:/wwwroot/ytecn.com/ui/"; $list=GetDirsInDir($url); print_r($lis...