PHP实现RSA分段加密

文章目录

    • 背景
    • Java RSA分段加密
    • PHP实现RSA分段加密
    • 校验
      • 编写RSA分段加密Java Demo
      • 编写RSA分段加密PHP Demo
      • 编写Java RSA分段解密Demo
      • 编写PHP RSA分段解密DEMO

背景

  1. 对接第三方金融支付系统接口,对方使用的是Java开发的,提供的Demo也是Java语言的。而公司使用的是PHP,所以需要将Demo中的加密转化成PHP实现。

Java RSA分段加密

  1. Java源码
public class RSAUtils {

    public static final String KEY_ALGORITHM = "RSA";

    public static final String SIGNATURE_ALGORITHM = "MD5withRSA";

    private static final int MAX_ENCRYPT_BLOCK = 117;

    private static final int MAX_DECRYPT_BLOCK = 128;

    /**
     * 

* 生成密钥对(公钥和私钥) *

* * @return * @throws Exception */
public static Map<String, Object> genKeyPair() throws Exception { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); keyPairGen.initialize(1024); KeyPair keyPair = keyPairGen.generateKeyPair(); RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); Map<String, Object> keyMap = new HashMap<String, Object>(2); keyMap.put(PUBLIC_KEY, publicKey); keyMap.put(PRIVATE_KEY, privateKey); return keyMap; } /** *

* 用私钥对信息生成数字签名 *

* * @param data * 已加密数据 * @param privateKey * 私钥(BASE64编码) * * @return * @throws Exception */
public static String sign(byte[] data, String privateKey) throws Exception { byte[] keyBytes = Base64.decodeBase64(privateKey); PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); PrivateKey privateK = keyFactory.generatePrivate(pkcs8KeySpec); Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); signature.initSign(privateK); signature.update(data); return Base64.encodeBase64String(signature.sign()); } /** *

* 校验数字签名 *

* * @param data * 已加密数据 * @param publicKey * 公钥(BASE64编码) * @param sign * 数字签名 * * @return * @throws Exception * */
public static boolean verify(byte[] data, String publicKey, String sign) throws Exception { byte[] keyBytes = Base64.decodeBase64(publicKey); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); PublicKey publicK = keyFactory.generatePublic(keySpec); Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); signature.initVerify(publicK); signature.update(data); return signature.verify(Base64.decodeBase64(sign)); } /** *

* 私钥解密 *

* * @param encryptedData * 已加密数据 * @param privateKey * 私钥(BASE64编码) * @return * @throws Exception */
public static byte[] decryptByPrivateKey(byte[] encryptedData, String privateKey) throws Exception { byte[] keyBytes = Base64.decodeBase64(privateKey); PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); Key privateK = keyFactory.generatePrivate(pkcs8KeySpec); Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, privateK); int inputLen = encryptedData.length; ByteArrayOutputStream out = new ByteArrayOutputStream(); int offSet = 0; byte[] cache; int i = 0; // 对数据分段解密 while (inputLen - offSet > 0) { if (inputLen - offSet > MAX_DECRYPT_BLOCK) { cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK); } else { cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet); } out.write(cache, 0, cache.length); i++; offSet = i * MAX_DECRYPT_BLOCK; } byte[] decryptedData = out.toByteArray(); out.close(); return decryptedData; } /** *

* 公钥解密 *

* * @param encryptedStr * 已加密数据 * @param publicKey * 公钥(BASE64编码) * @return * @throws Exception */
public static String decryptByPublicKey(String encryptedStr, String publicKey) throws Exception { byte[] encryptedData = Base64.decodeBase64(encryptedStr); System.out.println(encryptedData.length); byte[] keyBytes = Base64.decodeBase64(publicKey); X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); Key publicK = keyFactory.generatePublic(x509KeySpec); Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, publicK); int inputLen = encryptedData.length; ByteArrayOutputStream out = new ByteArrayOutputStream(); int offSet = 0; byte[] cache; int i = 0; // 对数据分段解密 while (inputLen - offSet > 0) { if (inputLen - offSet > MAX_DECRYPT_BLOCK) { cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK); } else { cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet); } out.write(cache, 0, cache.length); i++; offSet = i * MAX_DECRYPT_BLOCK; } byte[] decryptedData = out.toByteArray(); out.close(); return new String(decryptedData); } /** *

* 公钥加密 *

* * @param data * 源数据 * @param publicKey * 公钥(BASE64编码) * @return * @throws Exception */
public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception { byte[] keyBytes = Base64.decodeBase64(publicKey); X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); Key publicK = keyFactory.generatePublic(x509KeySpec); // 对数据加密 Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, publicK); int inputLen = data.length; ByteArrayOutputStream out = new ByteArrayOutputStream(); int offSet = 0; byte[] cache; int i = 0; // 对数据分段加密 while (inputLen - offSet > 0) { if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); } else { cache = cipher.doFinal(data, offSet, inputLen - offSet); } out.write(cache, 0, cache.length); i++; offSet = i * MAX_ENCRYPT_BLOCK; } byte[] encryptedData = out.toByteArray(); out.close(); return encryptedData; } /** *

* 私钥加密 *

* * @param data * 源数据 * @param privateKey * 私钥(BASE64编码) * @return * @throws Exception */
public static String encryptByPrivateKey(byte[] data, String privateKey) throws Exception { byte[] keyBytes = Base64.decodeBase64(privateKey); PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); Key privateK = keyFactory.generatePrivate(pkcs8KeySpec); Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, privateK); int inputLen = data.length; ByteArrayOutputStream out = new ByteArrayOutputStream(); int offSet = 0; byte[] cache; int i = 0; // 对数据分段加密 while (inputLen - offSet > 0) { if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); } else { cache = cipher.doFinal(data, offSet, inputLen - offSet); } out.write(cache, 0, cache.length); i++; offSet = i * MAX_ENCRYPT_BLOCK; } byte[] encryptedData = out.toByteArray(); out.close(); System.out.println(encryptedData.length); return Base64.encodeBase64String(encryptedData); } /** *

* 获取私钥 *

* * @param keyMap * 密钥对 * @return * @throws Exception */
public static String getPrivateKey(Map<String, Object> keyMap) throws Exception { Key key = (Key) keyMap.get(PRIVATE_KEY); return Base64.encodeBase64String(key.getEncoded()); } /** *

* 获取公钥 *

* * @param keyMap * 密钥对 * @return * @throws Exception */
public static String getPublicKey(Map<String, Object> keyMap) throws Exception { Key key = (Key) keyMap.get(PUBLIC_KEY); return Base64.encodeBase64String(key.getEncoded()); } }

PHP实现RSA分段加密

  1. 分析源码,发现RSA加密是使用分段加密,以下为PHP的写法
/**
 *
 * Created by PhpStorm.
 * User: wangxinhuang
 * Date: 2019-10-09
 * Time: 19:28
 *
 * @package App\Helpers
 */
class RSA
{
    public $privateKey = './rsa_private_key.pem';           //私钥地址
    public $publicKey = './rsa_public_key.pem';             //公钥地址

    public $pri_key = '';
    public $pub_key = '';

    /**
     * RSA constructor.
     * @param null $publicKeyPath
     * @param null $privateKeyPath
     * @param null $publicKey
     * @param null $privateKey
     * @throws FileNotFoundException
     */
    public function __construct($publicKeyPath=null, $privateKeyPath=null, $publicKey=null, $privateKey=null) {

        if ($this->checkKeyFile($publicKeyPath)) {
            $this->pub_key = openssl_pkey_get_public(file_get_contents($publicKeyPath));
        }

        if ($this->checkKeyFile($privateKeyPath)) {
            $this->pri_key = openssl_pkey_get_private(file_get_contents($privateKeyPath));
        }

        if (!is_null($publicKey)) {
            $this->pub_key = openssl_pkey_get_public($this->formatterPublicKey($publicKey));
        }

        if (!is_null($privateKey)) {
            $this->pri_key = openssl_pkey_get_private($this->formatterPrivateKey($privateKey));
        }

    }

    /**
     * 校验文件是否存在
     * @param $keyPath string 文件路径
     * @return bool
     * @throws FileNotFoundException
     */
    public function checkKeyFile($keyPath)
    {
        if (!is_null($keyPath)) {
            if(!file_exists($keyPath)) {
                throw new FileNotFoundException($keyPath);
            }

            return true;
        }

        return false;
    }

    /**
     * 格式化公钥
     * @param $publicKey string 公钥
     * @return string
     */
    public function formatterPublicKey($publicKey)
    {
        if (str_contains('-----BEGIN PUBLIC KEY-----', $publicKey)) return $publicKey;

        $str = chunk_split($publicKey, 64, PHP_EOL);//在每一个64字符后加一个\n
        $publicKey = "-----BEGIN PUBLIC KEY-----".PHP_EOL.$str."-----END PUBLIC KEY-----";

        return $publicKey;
    }

    /**
     * 格式化私钥
     * @param $privateKey string 公钥
     * @return string
     */
    public function formatterPrivateKey($privateKey)
    {
        if (str_contains('-----BEGIN RSA PRIVATE KEY-----', $privateKey)) return $privateKey;

        $str = chunk_split($privateKey, 64, PHP_EOL);//在每一个64字符后加一个\n
        $privateKey = "-----BEGIN RSA PRIVATE KEY-----".PHP_EOL.$str."-----END RSA PRIVATE KEY-----";

        return $privateKey;
    }

    /**
     *  私钥加密(分段加密)
     *  emptyStr    需要加密字符串
     */
    public function encrypt($str) {
        $crypted = array();
//        $data = json_encode($str);
        $data = $str;
        $dataArray = str_split($data, 117);
        foreach($dataArray as $subData){
            $subCrypted = null;
            openssl_private_encrypt($subData, $subCrypted, $this->pri_key);
            $crypted[] = $subCrypted;
        }
        $crypted = implode('',$crypted);
        return base64_encode($crypted);
    }

    /**
     *  公钥解密(分段解密)
     *  @encrypstr  加密字符串
     */
    public function decrypt($encryptstr) {
        // echo $encryptstr;exit;
        $encryptstr = base64_decode($encryptstr);
        $decrypted = array();
        $dataArray = str_split($encryptstr, 128);

        foreach($dataArray as $subData){
            $subDecrypted = null;
            openssl_public_decrypt($subData, $subDecrypted, $this->pub_key);
            $decrypted[] = $subDecrypted;
        }
        $decrypted = implode('',$decrypted);
        // openssl_public_decrypt(base64_decode($encryptstr),$decryptstr,$this->pub_key);
        return $decrypted;
    }

}

校验

  1. 生成rsa公钥和私钥
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUsGtqVZ5+EG1cWjSYP9bLnZhm
S93hThDjJPyC2oE51zTbXVeqTrJQTqeUQXfd03TGYP+CmgIpbsjn4PlmxMUu4YP3
D1xIlX4RfuDvt/bhpqGI5cQALNHa/mTAGI4mflyofH7nLQ+5kWBJK+6Qb6kG3ESA
8iWaSiG8qLXBbnV1XwIDAQAB
-----END PUBLIC KEY-----
-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANSwa2pVnn4QbVxa
NJg/1sudmGZL3eFOEOMk/ILagTnXNNtdV6pOslBOp5RBd93TdMZg/4KaAiluyOfg
+WbExS7hg/cPXEiVfhF+4O+39uGmoYjlxAAs0dr+ZMAYjiZ+XKh8fuctD7mRYEkr
7pBvqQbcRIDyJZpKIbyotcFudXVfAgMBAAECgYAJwJEcThK3Ww94pZY1yO+TZIWB
Y0coNoklsSN26If2W/zLdis33uXkMscSUDIr1K9NDVOJ7H/e4HqLz1AAO1ODLmFx
flnyeEIKan6M/4NA8/7IF+Wu0FDQjNm2iKW68axKiW01j6yqq2JagG9kff5xbkzx
riuWpmiDF0TWxzm6aQJBAPB2asI5dVr7bBC+sK7FjPQGNIu6X2NHeacHzUswSo7b
4NgTucAkubjLTgpd3s8/FQoVBm4Ay7Juzc0DBjVUv2UCQQDibpd6lzY0E9cNGol8
3HDKJGUTmnpduE9PKYua019vx/tgoMOK4squqnV74IY7NkhP5V0djO0XYxD0EaFn
mV9zAkAkp4hijuuqsMSqUMcR/R8dW4zK99/ufEi5A2Fx4qya1j2R8n/QIEkHOEZv
IhwCr3T/knDmd8yVKHrKk3lwy7hZAkEAlB7SGpCGFaUQ3XKJk9NEOQd700oPV/V0
dA1yVHKHEMFaMIiZweW/vmild8aVKHDG9vTMZ8NDaTQV6AMMeY+7/wJBANeLmqSH
flwpMA9BdyTxmuRv8W2lLKsjGDBDnVaKf4hBltMll/e3/OPkg/BPew3lxrHkp3E1
I6RyMTzmQxwXd78=
-----END PRIVATE KEY-----

编写RSA分段加密Java Demo

  1. 编写Java Demo
String key = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANSwa2pVnn4QbVxaNJg/1sudmGZL3eFOEOMk/ILagTnXNNtdV6pOslBOp5RBd93TdMZg/4KaAiluyOfg+WbExS7hg/cPXEiVfhF+4O+39uGmoYjlxAAs0dr+ZMAYjiZ+XKh8fuctD7mRYEkr7pBvqQbcRIDyJZpKIbyotcFudXVfAgMBAAECgYAJwJEcThK3Ww94pZY1yO+TZIWBY0coNoklsSN26If2W/zLdis33uXkMscSUDIr1K9NDVOJ7H/e4HqLz1AAO1ODLmFxflnyeEIKan6M/4NA8/7IF+Wu0FDQjNm2iKW68axKiW01j6yqq2JagG9kff5xbkzxriuWpmiDF0TWxzm6aQJBAPB2asI5dVr7bBC+sK7FjPQGNIu6X2NHeacHzUswSo7b4NgTucAkubjLTgpd3s8/FQoVBm4Ay7Juzc0DBjVUv2UCQQDibpd6lzY0E9cNGol83HDKJGUTmnpduE9PKYua019vx/tgoMOK4squqnV74IY7NkhP5V0djO0XYxD0EaFnmV9zAkAkp4hijuuqsMSqUMcR/R8dW4zK99/ufEi5A2Fx4qya1j2R8n/QIEkHOEZvIhwCr3T/knDmd8yVKHrKk3lwy7hZAkEAlB7SGpCGFaUQ3XKJk9NEOQd700oPV/V0dA1yVHKHEMFaMIiZweW/vmild8aVKHDG9vTMZ8NDaTQV6AMMeY+7/wJBANeLmqSHflwpMA9BdyTxmuRv8W2lLKsjGDBDnVaKf4hBltMll/e3/OPkg/BPew3lxrHkp3E1I6RyMTzmQxwXd78=";

try {
    JSONObject paramMap = new JSONObject();

    paramMap.put("name","张三");
    paramMap.put("idNo","342422165897654326");
    paramMap.put("phone","15256416396");
    paramMap.put("inAcctNo","8239472342342342");
    paramMap.put("inAcctBankName","平安银行");

    System.out.println(paramMap.toString());

    //获取加密参数
    String s = RSAUtils.encryptByPrivateKey(paramMap.toString().getBytes(), key);

    System.out.println(s);

}catch (Exception e){
    e.printStackTrace();

}
  1. 执行得到结果
{"phone":"15256416396","name":"张三","inAcctNo":"8239472342342342","idNo":"342422165897654326","inAcctBankName":"平安银行"}
129
256
gEtyoaEc+eaoyUng/rCzr3u27nPf7M610oBS6DGT225tEhNmAn+BsGp2FMYdzzQsAJyLoanWGs10ScTsWu6aIs2vUb1Eknm6q7EOhik5ISWjWemL+VYOOqLdtskNEL+LvUo4uVjd9pkCQtGQvNxmM8uhSZQ1o3b4q0vpcP/h6+UaQlQArKxEd2oophqEdP57I30sc9ICd0E8o6qIp4jHqDUiig+xyHFMBOnhbt/9Lc+IlEjENWs23XAZCilC0rlBfHVf3avB9on4t6ExpmKMrRV0Ojn6KjsBcsdnVpNGsERljsW05GK+A+1R++yYCDkmG6UDJxUq0i54fbw2+rLu0g==

编写RSA分段加密PHP Demo

  1. PHP Demo源码
$privateKey = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANSwa2pVnn4QbVxaNJg/1sudmGZL3eFOEOMk/ILagTnXNNtdV6pOslBOp5RBd93TdMZg/4KaAiluyOfg+WbExS7hg/cPXEiVfhF+4O+39uGmoYjlxAAs0dr+ZMAYjiZ+XKh8fuctD7mRYEkr7pBvqQbcRIDyJZpKIbyotcFudXVfAgMBAAECgYAJwJEcThK3Ww94pZY1yO+TZIWBY0coNoklsSN26If2W/zLdis33uXkMscSUDIr1K9NDVOJ7H/e4HqLz1AAO1ODLmFxflnyeEIKan6M/4NA8/7IF+Wu0FDQjNm2iKW68axKiW01j6yqq2JagG9kff5xbkzxriuWpmiDF0TWxzm6aQJBAPB2asI5dVr7bBC+sK7FjPQGNIu6X2NHeacHzUswSo7b4NgTucAkubjLTgpd3s8/FQoVBm4Ay7Juzc0DBjVUv2UCQQDibpd6lzY0E9cNGol83HDKJGUTmnpduE9PKYua019vx/tgoMOK4squqnV74IY7NkhP5V0djO0XYxD0EaFnmV9zAkAkp4hijuuqsMSqUMcR/R8dW4zK99/ufEi5A2Fx4qya1j2R8n/QIEkHOEZvIhwCr3T/knDmd8yVKHrKk3lwy7hZAkEAlB7SGpCGFaUQ3XKJk9NEOQd700oPV/V0dA1yVHKHEMFaMIiZweW/vmild8aVKHDG9vTMZ8NDaTQV6AMMeY+7/wJBANeLmqSHflwpMA9BdyTxmuRv8W2lLKsjGDBDnVaKf4hBltMll/e3/OPkg/BPew3lxrHkp3E1I6RyMTzmQxwXd78=';

$rsa = new RSA(null, null, null, $privateKey);

// 读取pem文件
// $rsa = new RSA(null, public_path('rsa_private_key.pem'));

$string = '{"phone":"15256416396","name":"张三","inAcctNo":"8239472342342342","idNo":"342422165897654326","inAcctBankName":"平安银行"}';

$encryptstr = $rsa->encrypt($string);

echo $encryptstr;
  1. 运行,得到结果,和Java代码执行的结果一致,所以两个结果是一样的
gEtyoaEc+eaoyUng/rCzr3u27nPf7M610oBS6DGT225tEhNmAn+BsGp2FMYdzzQsAJyLoanWGs10ScTsWu6aIs2vUb1Eknm6q7EOhik5ISWjWemL+VYOOqLdtskNEL+LvUo4uVjd9pkCQtGQvNxmM8uhSZQ1o3b4q0vpcP/h6+UaQlQArKxEd2oophqEdP57I30sc9ICd0E8o6qIp4jHqDUiig+xyHFMBOnhbt/9Lc+IlEjENWs23XAZCilC0rlBfHVf3avB9on4t6ExpmKMrRV0Ojn6KjsBcsdnVpNGsERljsW05GK+A+1R++yYCDkmG6UDJxUq0i54fbw2+rLu0g==

编写Java RSA分段解密Demo

  1. Java Demo
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUsGtqVZ5+EG1cWjSYP9bLnZhmS93hThDjJPyC2oE51zTbXVeqTrJQTqeUQXfd03TGYP+CmgIpbsjn4PlmxMUu4YP3D1xIlX4RfuDvt/bhpqGI5cQALNHa/mTAGI4mflyofH7nLQ+5kWBJK+6Qb6kG3ESA8iWaSiG8qLXBbnV1XwIDAQAB";

String input = "gEtyoaEc+eaoyUng/rCzr3u27nPf7M610oBS6DGT225tEhNmAn+BsGp2FMYdzzQsAJyLoanWGs10ScTsWu6aIs2vUb1Eknm6q7EOhik5ISWjWemL+VYOOqLdtskNEL+LvUo4uVjd9pkCQtGQvNxmM8uhSZQ1o3b4q0vpcP/h6+UaQlQArKxEd2oophqEdP57I30sc9ICd0E8o6qIp4jHqDUiig+xyHFMBOnhbt/9Lc+IlEjENWs23XAZCilC0rlBfHVf3avB9on4t6ExpmKMrRV0Ojn6KjsBcsdnVpNGsERljsW05GK+A+1R++yYCDkmG6UDJxUq0i54fbw2+rLu0g==";

String result = null;
try {
    result = RSAUtils.decryptByPublicKey(input, publicKey);
} catch (Exception e) {
    e.printStackTrace();
}

System.out.println(result);
  1. 输出结果
{"phone":"15256416396","name":"张三","inAcctNo":"8239472342342342","idNo":"342422165897654326","inAcctBankName":"平安银行"}

编写PHP RSA分段解密DEMO

  1. PHP Demo
$publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUsGtqVZ5+EG1cWjSYP9bLnZhmS93hThDjJPyC2oE51zTbXVeqTrJQTqeUQXfd03TGYP+CmgIpbsjn4PlmxMUu4YP3D1xIlX4RfuDvt/bhpqGI5cQALNHa/mTAGI4mflyofH7nLQ+5kWBJK+6Qb6kG3ESA8iWaSiG8qLXBbnV1XwIDAQAB';

$rsa = new RSA(null, null, $publicKey);

$inputStr = 'gEtyoaEc+eaoyUng/rCzr3u27nPf7M610oBS6DGT225tEhNmAn+BsGp2FMYdzzQsAJyLoanWGs10ScTsWu6aIs2vUb1Eknm6q7EOhik5ISWjWemL+VYOOqLdtskNEL+LvUo4uVjd9pkCQtGQvNxmM8uhSZQ1o3b4q0vpcP/h6+UaQlQArKxEd2oophqEdP57I30sc9ICd0E8o6qIp4jHqDUiig+xyHFMBOnhbt/9Lc+IlEjENWs23XAZCilC0rlBfHVf3avB9on4t6ExpmKMrRV0Ojn6KjsBcsdnVpNGsERljsW05GK+A+1R++yYCDkmG6UDJxUq0i54fbw2+rLu0g==';

$result = $rsa->decrypt($inputStr);

echo $result;
  1. 输出结果
{"phone":"15256416396","name":"张三","inAcctNo":"8239472342342342","idNo":"342422165897654326","inAcctBankName":"平安银行"}

你可能感兴趣的:(PHP)