English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
La funzione openssl_pkey_get_public() viene utilizzata per estrarre la chiave pubblica dal certificato per l'uso.
openssl_pkey_get_public()La funzione restituirà la tua chiave pubblica.
La funzione openssl_pkey_get_public() restituisce la chiave pubblica dal certificato fornito, in modo da poter essere utilizzata insieme ad altre funzioni.
openssl_pkey_get_public ( mixed $certificate ) : resource
Numero | Parametro | Descrizione |
---|---|---|
1 | certificate | Puoi utilizzare i seguenti certificati: 1. Risorsa del certificato X.509 2. Chiave pubblica proveniente da un file, formato file://path/to/file.pem. 3. Chiave pubblica in formato PEM. |
Se non ci sono errori, la funzione PHP openssl_pkey_get_public() restituirà un identificatore di risorsa positivo. Se fallisce, restituirà false.
Questa funzione funzionerà a partire dalla versione PHP maggiore di 5.0.0.
Funzionamento di openssl_pkey_get_public() con certificato X.509
<?php $dn = array( "countryName" => "IN", "stateOrProvinceName" => "Karnataka", "localityName" => "test1", "organizationName" => "test2", "organizationalUnitName" => "test3", "commonName" => "www.test.com", "emailAddress" => "[email protected]" ); // Generare una nuova coppia di chiavi privata/pubblica $privkey = openssl_pkey_new(); // Generare un certificato $csr = openssl_csr_new($dn, $privkey, array('digest_alg' => 'sha256')); $res_cert = openssl_csr_sign($csr, null, $privkey, 365); openssl_x509_export($res_cert, $x_509_certificate); echo $res_pubkey = openssl_pkey_get_public($x_509_certificate); ?>
Risultato di output
Risorsa id #5
Funzionamento di openssl_pkey_get_public() con file .pem
<?php $dn = array( "countryName" => "IN", "stateOrProvinceName" => "Karnataka", "localityName" => "test1", "organizationName" => "test2", "organizationalUnitName" => "test3", "commonName" => "www.test.com", "emailAddress" => "[email protected]" ); // Generazione di una nuova coppia di chiavi privata/pubblica $privkey = openssl_pkey_new(); // Generazione del certificato $csr = openssl_csr_new($dn, $privkey, array('digest_alg' => 'sha256')); $res_cert = openssl_csr_sign($csr, null, $privkey, 365); openssl_x509_export_to_file($res_cert, 'C:/xampp/htdocs/modules/openssl/x_509.pem'); echo $res_pubkey = openssl_pkey_get_public(file_get_contents('C:/xampp/htdocs/modules/openssl/x_509.pem')); ?>
Risultato di output
Risorsa id #7