本文介绍了openssl_pkey_get_public未打开公钥,“无起始行"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

生成公钥,然后使用函数 openssl_pkey_get_public - $ publicKeyResource = bool(false)和消息读取公钥时:错误:0906D06C:PEM例程:PEM_read_bio:无起始行

When generating public key and then reading it with function openssl_pkey_get_public - $publicKeyResource = bool(false) and message:error:0906D06C:PEM routines:PEM_read_bio:no start line

$privateKey = openssl_pkey_new(array('private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA));

$keyDetails = openssl_pkey_get_details($privateKey);

$publicKeyResource = openssl_pkey_get_public($keyDetails['key']);

怎么了?

P.S.

privateKey =

array(3) {
  ["bits"]=>int(2048)

  ["key"]=>
  string(451) "-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApo5lpSuSQmAOXfqAmexj
IzjdGnd1X1gCKj5ko2DHgcR4XBlj1hbFNs1pzXx+R/UvLXTeF7dNQ+9AgXjEeRa6
71VbNxrUgvb/PHjEANwce7xBsnbu+dcSazyNHzx4ahWyEF4f3HyaJkGrT/Dgzcut
DO+yFAH9u8Hx26cj/8kyrtIHxazemnD+IDHRa3zOjKDmTfoDRKtOMTPVgFAsYBXn
tKcLyamCSBgpwfQwKfUUcYhfY1xD9UMhVXabSSiNQOiTMuOIZUHueO8UCp/tdK6a
LprUDBQ/tVmiV7ZMeZYMjh6XnK7higJ3WZp8RmD4PPeKbtG6j2AuGpbF/ddzD62T
XwIDAQAB
-----END PUBLIC KEY-----
"

  ["type"]=>
  int(0)
}

推荐答案

使用phpseclib的Crypt_RSA可能会更轻松.例如.

You might have an easier time with phpseclib's Crypt_RSA. eg.

更多信息:

http://phpseclib.sourceforge.net/

这篇关于openssl_pkey_get_public未打开公钥,“无起始行"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:35