实现代码
$config = array(
"digest_alg" => "sha512",
"private_key_bits" => 1024, //字节数 512 1024 2048 4096 等
"private_key_type" => OPENSSL_KEYTYPE_RSA, //加密类型
);
$res = openssl_pkey_new($config);
$privKey = null;
openssl_pkey_export($res,$privKey,null,$config);
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey['key'];
openssl_private_encrypt($string,$encrypt_string,$privKey);
$encrypt_string = base64_encode($encrypt_string);