Skip to content

Instantly share code, notes, and snippets.

@charlycoste
Last active December 11, 2015 17:39
Show Gist options
  • Save charlycoste/4636511 to your computer and use it in GitHub Desktop.
Save charlycoste/4636511 to your computer and use it in GitHub Desktop.
<?php
class OpenSSL_PKey
{
protected $pkey;
public function __construct()
{
$this->pkey = openssl_pkey_new();
}
public function __toString()
{
$key = '';
openssl_pkey_export($this->pkey, $key);
return $key;
}
public function getDetails()
{
return openssl_pkey_get_details($this->pkey);
}
public function __destruct()
{
openssl_pkey_free($this->pkey);
}
}
<?php
class OpenSSLCert
{
protected $options;
protected $pkey;
public function __construct(OpenSSLCertOptions $options, OpenSSLKey $key)
{
$this->options = $options;
$this->pkey = $key;
}
}
<?php
class OpenSSLCertOptions
{
protected $availableKeys = array( "countryName",
"stateOrProvinceName",
"localityName",
"organizationName",
"organizationalUnitName",
"commonName",
"emailAddress" );
protected $dn = array();
public function __call($name, $args)
{
if (in_array($name, $this->availableKeys)) {
if (isset($args[0])) {
$this->dn[$name] = $args[0];
return $this;
} else {
return $this->dn[$name];
}
}
}
}
<?php
class OpenSSLManager
{
public function createNewKey()
{
return new PKey();
}
}
@charlycoste
Copy link
Author

openssl_pkey_get_private et openssl_pkey_get_public retournent des ressources de type "OpenSSL key"

openssl_pkey_export permet d'obtenir une clée sous forme d'une chaine de caractères

@charlycoste
Copy link
Author

openssl_sign prend une ressource de type "OpenSSL key" pour signer les données

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment