PHP 8.1.24 Released!

openssl_pkcs12_read

(PHP 5 >= 5.2.2, PHP 7, PHP 8)

openssl_pkcs12_readParse a PKCS#12 Certificate Store into an array

Descrição

openssl_pkcs12_read(string $pkcs12, array &$certificates, string $passphrase): bool

openssl_pkcs12_read() parses the PKCS#12 certificate store supplied by pkcs12 into a array named certificates.

Parâmetros

pkcs12

The certificate store contents, not its file name.

certificates

On success, this will hold the Certificate Store Data.

passphrase

Encryption password for unlocking the PKCS#12 file.

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Exemplos

Exemplo #1 openssl_pkcs12_read() example

<?php
if (!$cert_store = file_get_contents("/certs/file.p12")) {
echo
"Error: Unable to read the cert file\n";
exit;
}

if (
openssl_pkcs12_read($cert_store, $cert_info, "my_secret_pass")) {
echo
"Certificate Information\n";
print_r($cert_info);
} else {
echo
"Error: Unable to read the cert store.\n";
exit;
}
?>
add a note

User Contributed Notes 4 notes

up
5
Rovinson
26 days ago
In response to Anonymous' note:(https://www.php.net/manual/es/function.openssl-pkcs12-read.php#128819)

In PHP versions 8.2.6 and 8.2.7, OpenSSL 1.1.1 is still utilized. However, starting from PHP version 8.2.8 onwards, OpenSSL 3.0.9 is employed.

I have conducted tests, and the function works correctly with all PHP versions using OpenSSL 1, but it fails with OpenSSL 3 versions.
up
4
Anonymous
1 month ago
The openssl_pkcs12_read method does not work in PHP 8.2 due to the change in the OpenSSL library from version ^1 to ^3.
up
1
Also Anonymous
1 month ago
In response to Anonymous' note:(https://www.php.net/manual/en/function.openssl-pkcs12-read.php#128790)

I'm using 8.2.6 on Windows and this function is working without issue.
up
0
InvisibleSmiley
2 days ago
It really seems to depend on the OpenSSL version only. I checked:

OpenSSL 1:
- Linux Sury PHP 8.1 and 8.2
- Windows (according to what Anonymous reported here)

OpenSSL 3:
- Linux Ubuntu jammy (22.04 LTS) PHP 8.1
- Mac OS Homebrew PHP 8.1 and 8.2
To Top