OpenSSL public/private key generation tools.

author Barry O'Donovan
author The Skilled Team of PHP Developers at Open Solutions
category OSS
package OSS_Crypt
copyright Copyright (c) 2007 - 2012, Open Source Solutions Limited, Dublin, Ireland
license New BSD License

 Methods

Exports self signed certificate as string.

exportCert() : string

Converts self signed certificate to string, and returns it.

Exceptions

\OSS_Crypt_Exception if $_cert is not generated.

Returns

string

Exports key pair.

exportKeyPair(\boo $encrypt) : resource

Exports key pair which is actually private key which store public key information. If encrypt is set to true then export resource will be encrypted with $_passphrase else it will return the actual key without encryption. By default $encrypt is true.

Parameters

$encrypt

\boo

The encrypt flag to encrypt or not the returning resource.

Exceptions

\OSS_Crypt_Exception if $_keypair is not generated, or if encryption required and $_passphrase is not unset.

Returns

resourceof key pair

Exports public.

exportPublicKey() : resource

Exports public key from $_keypair.

Exceptions

\OSS_Crypt_Exception if $_keypair is not generated.

Returns

resourceof public key

Generates sertificate for given information

genCertificate(array $dn, $options) : resource
oaram array|null $options Options for creating certificate

Parameters

$dn

array

Certificate information

$options

Returns

resource

Generates key pair.

genKeyPair(array $options) : resource

Generates public and private key pair for encryption / decryption.

Parameters

$options

array

The generator options.

Returns

resourceof key pair

Generates self signed certificate and returns it.

genSelfSignedCert(array $dn, int $days, array | null $options, int $serial) : resource

Parameters

$dn

array

Certificate information

$days

int

Days until certificate expires

$options

arraynull

Options for creating certificate

$serial

int

Serial number by default is 0

Returns

resourceof certificate.

Generates self signed certificate and returns it.

genSignedCert(array $dn, int $days, string $cacert, string $cakey, array | null $options, int $serial) : resource

Parameters

$dn

array

Certificate information

$days

int

Days until certificate expires

$cacert

string

Encrypted issuer certifcate

$cakey

string

Encrypted issuer private key

$options

arraynull

Options for creating certificate

$serial

int

Serial number by default is 0

Returns

resourceof certificate.

Parses encrypted certificate

parseCertificate(string $cert) : array
Static

Parameters

$cert

string

Encrypted certificate

Returns

array

Sets key pair.

setKeyPair(string $keypair) : resource

Sets key pair from key pair file content

Parameters

$keypair

string

The key pair file content

Returns

resourceof key pair

Sets passphrase.

setPassphrase(string $passphrase) : void

Sets passphrase which will be used for key pair encryption.

Parameters

$passphrase

string

The passphrase for key pair encryption

 Properties

 

A variable to hold a certificate resource

$_cert : resource
 

A variable to hold a key pair resource

$_keypair : resource
 

A variable to store a Passphrase to encrypt / decrypt the key pair

$_passphrase : string