zoukankan      html  css  js  c++  java
  • php SHA256WithRSA 签名验签&加密解密

    废话不多说,直接上代码!

    使用:

    $pri_key =""
    $pub_key = "";
    $char = '方方块儿';//要加密的字符
    $sign = $this->RsaEncrypt($char,$pri_key);//加密结果
     $result = $this->RsaDecrypt($sign,$pub_key);//对加密结果进行解密

    方法:

    加密:
    
    public function RsaEncrypt($str,$pri_key){
            $pi_key =openssl_pkey_get_private($pri_key);
            if(!$pi_key)return false;//秘钥不可用
            openssl_private_encrypt($str,$encrypted,$pi_key);
            $encrypted =base64_encode($encrypted);
            return $encrypted;
    }
    
    解密:
    public function RsaDecrypt($str,$pub_key){
            $pu_key =openssl_pkey_get_public($pub_key);
            if(!$pu_key)return false;//秘钥不可用
            openssl_public_decrypt(base64_decode($str),$decrypted,$pu_key);
            return $decrypted;
    }

    注:开启PHP的php_openssl扩展

    滴水成冰,世间不存在毫无意义的付出,时间终会给你答案。
  • 相关阅读:
    AWS 移动推送到iOS设备,Amazon Pinpoint
    iOS 上架注意
    iOS 开发笔记
    TestFlight 测试
    iOS UI基础-21 WKWebView
    Parallels Desktop 重装系统
    Xcode8.2 继续使用插件
    iOS JSPatch 热修复使用
    Mac 配置环境变量
    Mac 安装 JDK
  • 原文地址:https://www.cnblogs.com/soupig/p/15054534.html
Copyright © 2011-2022 走看看