php rsa分段加密算法

   public function rsaEncrypt($resData,$pubKey) {
     
        $res = openssl_pkey_get_public(file_get_contents($pubKey));
        $tmpStr = '';
        foreach($resData as $k=>$v){
     
            $tmpStr = $tmpStr.$k.'='.$v.'&';
        }
        $rawData = substr($tmpStr,0,-1);
        $keyInfo = openssl_pkey_get_details($res);
        $step = $keyInfo['bits'] / 8 - 11;
        $encryptedList = array();
        for ($i = 0, $len = strlen($rawData); $i < $len; $i += $step) {
     
            $data = substr($rawData, $i, $step);
            $encrypted = '';
            openssl_public_encrypt($data, $encrypted, $res);
            $encryptedList[] = ($encrypted);
        }
        openssl_free_key($res);
        $data = join('', $encryptedList);
        $data = base64_encode($data);
        // $data = str_replace(array('+','/','='),array('-','_',''),$data);
        return $data;
    }

你可能感兴趣的:(基础知识,封装方法,php,后端)