openssl_pkcs12_read()函数是PHP中的内置函数,由PKCS#12证书存储区使用,以将其转换为pkcs12提供的数组。 PKCS#12文件可能已加密并签名。
用法:
bool openssl_pkcs12_read( string $pkcs12, array &$certs, string $pass )
参数:此函数接受上述和以下描述的三个参数:
- $pkcs12:PKCS#12是RSA实验室发布的称为Public-Key密码学标准(PKCS)的标准系列之一。
- $certs:如果成功,它将包含证书存储信息。
- $pass:此参数用于解锁PKCS#12文件的加密密码。
返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。
例:
PHP
<?php
$dn = array(
"countryName" => 'xx',
"stateOrProvinceName" => 'uttar prradesh',
"localityName" => 'varanasi',
"organizationName" => 'geeksforgeeks',
"organizationalUnitName" => 'geeks team',
"commonName" => 'people',
"emailAddress" => 'user@geeks.com'
);
$privateKeyPass = 'dummyPassword';
$numberOfDays = 108;
$privateKey = openssl_pkey_new();
$csr = openssl_csr_new($dn, $privateKey);
// Create a csr file, change null to
// a filename to save
$sscert = openssl_csr_sign($csr,
null, $privateKey, $numberOfDays);
// On success $publicKey will hold
// the PEM content
openssl_x509_export($sscert, $publicKey);
// Export the privateKey as a PEM content
openssl_pkey_export($privateKey,
$privateKey, $privateKeyPass);
// Parses the $privateKey and used by
// openssl_pkcs12_export_to_file.
$key = openssl_pkey_get_private(
$privateKey, $privateKeyPass);
$certificateOutput = null;
// Save the pfx file to $certificateOutput
openssl_pkcs12_export($sscert,
$certificateOutput, $key, $privateKeyPass);
// openssl_pkcs12_read reads the pkcs12
// certificate and store into array
openssl_pkcs12_read ($certificateOutput,
$readableOutput, $privateKeyPass );
var_dump($readableOutput);
?>
输出:
array(2) { ["cert"]=> string(1444) "-----BEGIN CERTIFICATE----- MIID/DCCAuSgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBljELMAkGA1UEBhMCeHgx FzAVBgNVBAgMDnV0dGFyIHBycmFkZXNoMREwDwYDVQQHDAh2YXJhbmFzaTEWMBQG A1UECgwNZ2Vla3Nmb3JnZWVrczETMBEG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u7qyUSx/zE9ehUg0MDXcNkauSYfD+1BbIlyQSRaZhGYiKJ5f3 jJuTqS3W4zkPvxLKc2cSGJb1RQKBgQDOoicPFut1SpIW/wVhzoxXfM8IvyW3KlnE PaqPLFLh5PomiQVhcvd0fKm6FV3sjVI7I++TYzKcpix8V+B2axSTuHrsYCNNGz8L BE7pOMbEZVE+SPwYT8G15QdiAKxITbNz1YkxB9yBarpAoRw4THAtpnhZhclAzBj5 0dwwTN+YFwKBgQCWXDZgfTE1Eb/YSxZtvw2RBgywt808UxCzuJeIHprNwh7oCvhv ZPPM7nLw/C7NwEa3UAZmF1Z0XPOyBv2TLPNREYk1pNlWJfCtGQe7H0s/NsJhjzFq htlelv0Zp2E4+Uqt/GvesRzZaMU9TId8HoYJqNQk1prv1ih09TKFypdyUQKBgHbT CnED9hz55+6vcjHfbBb3X7sg6JhfE0XlTEqO646ZdTxpuR1j1mc3NQccOGnKjsoR jTiNZ9JrQNO0WRDf3PJhuNZrJoG1tFgqfxJgovTXapPNtqJoYvWtocQ6rNfbTuHC nuUCJ0yIylhWDXtWgX/O5hBc/fF0LLykcOGZo067AoGACL/iSs8wNse15sEJ1OdT SNgL4AnwzyP/wnyIEN57GVhJV9XJCuhlUDhQhn1dRVKmsi3pWMlPldZYgdiZGH6y 9p12cXSJywVIdwszld3OpXhFS+TwMTbAm49qHtvP2TovsPJpEHLXDBEZBo7k1oHU Uu3UyCB/z8dWkOINHWoi5/0= -----END PRIVATE KEY----- " }
相关用法
- PHP imagecreatetruecolor()用法及代码示例
- PHP fpassthru( )用法及代码示例
- PHP ImagickDraw getTextAlignment()用法及代码示例
- PHP Ds\Sequence last()用法及代码示例
- PHP Imagick floodFillPaintImage()用法及代码示例
- PHP array_udiff_uassoc()用法及代码示例
- PHP geoip_continent_code_by_name()用法及代码示例
- PHP GmagickPixel setcolor()用法及代码示例
- PHP opendir()用法及代码示例
- PHP cal_to_jd()用法及代码示例
- PHP stream_get_transports()用法及代码示例
- PHP Ds\Deque pop()用法及代码示例
- PHP SimpleXMLElement children()用法及代码示例
- PHP array_intersect_ukey()用法及代码示例
- PHP is_numeric()用法及代码示例
- PHP Imagick adaptiveSharpenImage()用法及代码示例
- PHP XMLWriter endDtdEntity()用法及代码示例
- PHP isset()用法及代码示例
注:本文由纯净天空筛选整理自shubham_singh大神的英文原创作品 PHP openssl_pkcs12_read() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。