為了加解密 我寫了兩個function
這是加密
function RsaEncode($msg,$publicKey){
$temp = str_split($msg,117);
$payload = array();
foreach ($temp as $key => $value) {
openssl_public_encrypt($value, $encrypted, $publicKey);
array_push($payload, $encrypted);
}
$payload =implode($payload);
$payload= base64_encode($payload);
return $payload;
}
這是解密
function RsaDecode($response,$publicKey){
$payload = array();
$payload2 = base64_decode($response);
$temp = str_split($payload2,125);
foreach ($temp as $key => $value) {
openssl_public_decrypt($value, $encrypted, $publicKey);
array_push($payload, $encrypted);
}
$payload =implode($payload);
$result = utf8_encode($payload);
return $result;
}
我用同樣的public key 加密沒問題
不過收到對方用private key 加密的密文後
用同樣的public key
openssl_public_decrypt解密卻一直失敗
回傳值都是false
請問openssl_public_decrypt會失敗是因為public key的關係
還是密文錯誤也會有影響?