ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
https://www.ianisme.com/ios/2515.html ~~~ protected function encrypt($originalData){ $crypto = ''; foreach (str_split($originalData, 117) as $chunk) { openssl_public_encrypt($chunk, $encryptData, $this->rsaPublicKey); $crypto .= $encryptData; } return $this->urlsafe_b64encode($crypto); } protected function decrypt($encryptData){ $crypto = ''; foreach (str_split($this->urlsafe_b64decode($encryptData), 128) as $chunk) { openssl_private_decrypt($chunk, $decryptData, $this->rsaPrivateKey); $crypto .= $decryptData; } return $crypto; } protected function urlsafe_b64encode($string) { $data = base64_encode($string); $data = str_replace(array('+','/','='),array('-','_',''),$data); return $data; } protected function urlsafe_b64decode($string) { $data = str_replace(array('-','_'),array('+','/'),$string); $mod4 = strlen($data) % 4; if ($mod4) { $data .= substr('====', $mod4); } return base64_decode($data); } PHP使用 openssl 进行 RSA 数据加解密的时候有长度限制,加密长度不能超过117个字符,解密长度不能超过128个字符。这里我们可以对数据进行分割加解密后再拼接起来。 ~~~