openssl_pkey_get_private ( mixed $key [, string $passphrase = “” ] ) : resource
参数
key
key 可以是如下密钥之一:
如下格式的字符串 file://path/to/file.pem。该文件必须包含 PEM 编码的证书或者私钥 (可能都包含了).
一个 PEM 格式的私钥。
passphrase
如果指定的密钥已被加密了 (受密码保护),可选参数 passphrase 是必须要的。
返回值
成功,返回真实的密钥资源标识符,失败,返回 FALSE .
使用方法
// 第一种方法 在路径前面拼接 file:// (但是这里要注意的是,路径和 file:// 是两个部分,
// 绝对路径下 /home/***.pem 最终得到的应该是 file:///home/***.pem,
// 注意这个地方 file: 后面跟着是三个斜线 )
$privateKey = openssl_pkey_get_private('file://'.$privateKey);
// 第二种方法 用 file_get_contents 读取 .pem 文件传入进去
$privateKey = openssl_pkey_get_private(file_get_contents($privateKey));