public function RSA_pub_encode($data, $pu_key) {
$data = str_split($data, 117);
$str_rsa = '';
foreach ($data as $key => $v) {
openssl_public_encrypt($v, $encrypted, $pu_key);
$str_rsa.= $encrypted;
}
return base64_encode($str_rsa);
}
/*
* RSA解密
*/
public function RSA_decode($data, $pi_key) {
$xx = base64_decode($data);
// $pu_key = openssl_pkey_get_public($public_key); //这个函数可用来判断公钥是否是可用的
$pi_key = openssl_pkey_get_private($pi_key);
$xx = str_split($xx, 256);
$str_rsa = '';
foreach ($xx as $key => $v) {
openssl_private_decrypt($v, $decrypted, $pi_key); //私钥解密
$str_rsa.=$decrypted;
//$str_rsa = $str_rsa . $encrypted;
}
return $str_rsa;
}
加密后的字符串 如果 要使用get方式 传递 需要 urlencode