PHP openssl_error_string()函数
openssl_error_string ()函数是PHP中的一个内置函数,用于从 openSSL 库中获取最后一个错误。错误消息是排队的,所以应该多次调用这个函数来收集所有的信息。最后一个错误将是最近的错误。
句法:
openssl_error_string(): string|false
参数:此函数没有参数。
返回值:返回错误消息字符串,如果没有更多错误消息要返回,则返回 false。
下面的示例说明了PHP中的 openssl_error_string()函数。
示例 1:
PHP
PHP
"IN",
"stateOrProvinceName" => "Delhi",
"localityName" => "Delhi",
"organizationName" => "Geeks for geeks",
"organizationalUnitName" => "PHP Documentation Team",
"commonName" => "Geeks",
"emailAddress" => "wez@example.com"
);
// Generate a new private (and public) key pair
$privkey = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
));
// Generate a certificate signing request
$csr = openssl_csr_new($dn, $privkey, array(
'digest_alg' => 'sha256'
));
// Generate a self-signed cert,
// valid for 365 days
$x509 = openssl_csr_sign($csr,
null, $privkey, $days = 365, array(
'digest_alg' => 'sha256'
));
// Save your private key, CSR and
// self-signed cert for later use
dopenssl_pkey_export($privkey, $pkeyout, "mypassword")
and var_dump($pkeyout);
// Show any errors that occurred here
while (($e = openssl_error_string()) !== false) {
echo $e . "\n";
}
?>
输出:
SXuR6GPO5Kk6WJcS0zuG4A==
:::: Listed are open ssl error while encryption:::
error:0607A082:digital envelope routines:EVP_CIPHER_CTX_set_key_length:invalid key length
示例 2:
PHP
"IN",
"stateOrProvinceName" => "Delhi",
"localityName" => "Delhi",
"organizationName" => "Geeks for geeks",
"organizationalUnitName" => "PHP Documentation Team",
"commonName" => "Geeks",
"emailAddress" => "wez@example.com"
);
// Generate a new private (and public) key pair
$privkey = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
));
// Generate a certificate signing request
$csr = openssl_csr_new($dn, $privkey, array(
'digest_alg' => 'sha256'
));
// Generate a self-signed cert,
// valid for 365 days
$x509 = openssl_csr_sign($csr,
null, $privkey, $days = 365, array(
'digest_alg' => 'sha256'
));
// Save your private key, CSR and
// self-signed cert for later use
dopenssl_pkey_export($privkey, $pkeyout, "mypassword")
and var_dump($pkeyout);
// Show any errors that occurred here
while (($e = openssl_error_string()) !== false) {
echo $e . "\n";
}
?>
输出:
string(1854) “—–BEGIN ENCRYPTED PRIVATE KEY—–
MIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIPbMk8XYJMNECAggA
MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECFEhHuj2fzInBIIEyNt/L/HxdXnw
VJdlJUaG8He7uIjIa5b8/JVAjd1r5jZqLrSztNG5KiPUljGJxYzFTx/eyD6mmVp4
VrOnOrFyRwHBYQAJyTdEkYQ8J6ogBUdHY724uIIqHcbMo3hKFn0te8xDVWhn0klV
fdTbhJfGvYlU+HmJRmmR65Ser38CLsSxR55/TUx8PPUzY4683VdWS40AIQeCoeVe
yn68eN4ylbBWg0N9Zor3D8k8+qmOGTZp3RK69ddavIscEObDtw6iGDbxXa6Q9QC+
B7/u8wYRBTz0XMLapm4+JFi1F4cQZCFP7pC9VJwiGvfo4hYAT0P3S2eEzCZllF9N
mFNDjU1AIHpTSD87ZQr”…
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
参考: https://www. PHP.net/manual/en/函数.openssl-pkey-export。 PHP