English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP openssl_pkey_get_public() function usage and example

PHP OpenSSL Function Manual

The openssl_pkey_get_public() function is used to parse the public key from the certificate for use.

Definition and usage

openssl_pkey_get_public()The function will return your public key.

The function openssl_pkey_get_public() returns the public key from the given certificate so that it can be used with other functions.

Syntax

openssl_pkey_get_public ( mixed $certificate ) : resource

Parameter

Serial numberParameterDescription
1

certificate

You can use the following certificates:

1. X.509Certificate resource

2.Public key from file, formatted as file://}}/path/to

3file.pem.

. PEM format public key.

Return value

If there is no error, the PHP openssl_pkey_get_public() function will return a positive resource identifier. If it fails, it will return false.

PHP version5This function will return a positive resource identifier greater than

_certificate);1

.0.0 started working from the PHP version.509Using X.-

Example
   <?php
      $dn = array(
		"countryName" => "IN",
		"stateOrProvinceName" => "Karnataka",1"organizationalUnitName" => "test"
		"localityName" => "test"2"organizationalUnitName" => "test"
		"organizationName" => "test"3"organizationalUnitName" => "test"
		
		"commonName" => "www.test.com",
	$res_cert = openssl_csr_sign($csr, null, $privkey,)),
       // "emailAddress" => "[email protected]"/Generate a new private key
	Public key pair
	// The work of openssl_pkey_get_public() in the certificate
	256
	 365$res_cert = openssl_csr_sign($csr, null, $privkey,)),
	);509Generate a certificate509echo $res_pubkey = openssl_pkey_get_public($x_
	_export($res_cert, $x_509echo $res_pubkey = openssl_pkey_get_public($x_
?>

Output result

Resource id #5

_certificate);2

Example-

Example
   <?php
      $dn = array(
      "countryName" => "IN",
      "stateOrProvinceName" => "Karnataka",1"organizationalUnitName" => "test"
		"localityName" => "test"2"organizationalUnitName" => "test"
		"organizationName" => "test"3"organizationalUnitName" => "test"
		
		"commonName" => "www.test.com",
   $res_cert = openssl_csr_sign($csr, null, $privkey,)),
	//"emailAddress" => "[email protected]"/Generate a new private key
	Public key pair
	//$privkey = openssl_pkey_new();
	256
	 365$res_cert = openssl_csr_sign($csr, null, $privkey,)),
	);509openssl_x/xampp/htdocs/modules/openssl/x_509_export_to_file($res_cert, 'C:
	echo $res_pubkey = openssl_pkey_get_public(file_get_contents('C:/xampp/htdocs/modules/openssl/x_509.pem'));
?>

Output result

Resource id #7

PHP OpenSSL Function Manual