验证公钥私钥是否可用,并且得到私钥公钥对应得编号在解密加密时使用
$pu_key = openssl_pkey_get_public($public_key);
$privatekey = openssl_pkey_get_private($privatekey);
//公钥加密 $crypto = ''; foreach (str_split($data, 117) as $chunk) { openssl_public_encrypt($chunk, $encryptData, $pu_key); $crypto .= $encryptData; } $encrypted = base64_encode($crypto); //私钥解密 $crypto = ''; foreach (str_split($base64_decode($encrypted), 128) as $chunk) { openssl_private_decrypt($chunk, $decryptData, $pi_key); $crypto .= $decryptData; }
生签
openssl_sign($data,$sign,$pu_key);
openssl_varify($data,$sign,$pi_key);