function 私钥加密($加密前, $pi_key) {
$encrypted = '';
$plainText = str_split($加密前, 117);//将要加密的内容分段,每段最大长度为117
foreach ($plainText as $chunk) {
openssl_private_encrypt($chunk, $encryptedChunk, $pi_key, OPENSSL_PKCS1_PADDING);//私钥加密每段
$encrypted .= $encryptedChunk;//将每段加密后的内容拼接起来
}
$加密后 = base64_encode($encrypted);//将加密后的内容进行base64编码
return $加密后;
}
function 私钥解密($解密前, $pi_key) {
$decrypted = '';
$encrypted = base64_decode($解密前);//将加密后的内容进行base64解码
$cipherText = str_split($encrypted, 128);//将加密后的内容分段,每段最大长度为128
foreach ($cipherText as $chunk) {
openssl_private_decrypt($chunk, $decryptedChunk, $pi_key, OPENSSL_PKCS1_PADDING);//私钥解密每段
$decrypted .= $decryptedChunk;//将每段解密后的内容拼接起来
}
return $decrypted;
}
原创文章,作者:何故,如若转载,请注明出处:https://www.htm5.cn/1590.html