原来代码:
public function encrypt($data) {
if (openssl_public_encrypt(base64_encode($data), $encrypted, $this->pubkey))
$data = base64_encode($encrypted);
else
throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?'); return $data;
} public function decrypt($data) {
if (openssl_private_decrypt(base64_decode($data), $decrypted, $this->privkey))
$data = $decrypted;
else
$data = ''; return $data;
}
修改分段以后:
public function encrypt($originalData){
$crypto = '';
foreach (str_split($originalData, 117) as $chunk) {
openssl_public_encrypt($chunk, $encryptData, $this->pubkey);
$crypto .= $encryptData;
}
return base64_encode($crypto);
} public function decrypt($encryptData){
$crypto = '';
foreach (str_split(base64_decode($encryptData), 128) as $chunk) {
openssl_private_decrypt($chunk, $decryptData, $this->privkey);
$crypto .= $decryptData;
}
return $crypto;
}