📜  PHP openssl_error_string()函数

📅  最后修改于: 2022-05-13 01:56:38.219000             🧑  作者: Mango

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";
}
  
?>


输出:

示例 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";
}
  
?>

输出:

参考: https://www. PHP.net/manual/en/函数.openssl-pkey-export。 PHP