PHP Classes

PHP OpenSSL Proxy: Manage certificates and encrypt data using OpenSSL

Recommend this page to a friend!

  Author Author  
Picture of Adão Pedro
Name: Adão Pedro <contact>
Classes: 1 package by
Country: Angola Angola


  Detailed description   Download Download .zip .tar.gz  
This package can manage certificates and encrypt data using OpenSSL.

It can perform several operations with encrypted data using the PHP OpenSSL extension.

Currently, it can:

- Create self-signed certifications

- Export a certificate as a string or as an object

- Generate public and private keys from the details of a given institution

- Get a public key or a private key

- Sign data with a given key

- Verify if a data string encrypted with a given private key can be decrypted with the associated the public key

- Parse a certificate to extract its details as an object

- Check if a private key is from a given certificate

Details

php-openssl-proxy

About

A PHP wrapper around the OpenSSL extension that provides a user-friendly interface for dealing with OpenSSL.

What's up with the "proxy" name?

It is simply an analogy of the role of a proxy server - which acts as an intermediary.

Features

Create X.509, CSRs and CRLs certificates, Create RSA, HD and DSA keys, Generate and verify signatures, Encoding and decoding, Parsing x509 certificate.

Requirements

This library needs PHP 8 or greater, ext-openssl.

Installation

composer require adaopedro/php-openssl-proxy @dev

Example Usage

Creating a Self-Signed Certificate

use AdaoPedro\OpenSSLProxy\SSCertificate;

$ssCertificate = (new SSCertificate(
    days: 365, //expiration
))->setDistinguishNames(
        countryName: "AO",
        stateOrProvinceName: "Angola",
        localityName: "Luanda",
        organizationName: "A Pedro Developers (SU), Lda",
        organizationalUnitName: "AP",
        commonName: "apedrodevelopers",
        emailAddress: "contato@apdev.ao"
);

try {
    $ssCertificate->save();
} catch(\Exception $ex) {
    echo $ex->getMessage() . PHP_EOL;
}

Creating a CA-Signed Certificate

use AdaoPedro\OpenSSLProxy\CASCertificate;

$certificate = (new CASCertificate(
    days: 365, //expiration
    rootCertificate: $rootCertificate, //an instance of a Self-Signed Certificate, for example
))->setDistinguishNames(
        //...
);

try {
    $certificate->save();
} catch(\Exception $ex) {
    echo $ex->getMessage() . PHP_EOL;
}

Exporting a certificate as a string

//$certificate => an instance of SS or CAS Certificate
echo $certificate->getx509();

Exporting a certificate as an PHP OpenSSLCertificate object

//$certificate => an instance of SS or CAS Certificate
var_dump(
    $certificate->get()
);

Exporting public and private keys from a certificate

 //$certificate => an instance of SS or CAS Certificate
var_dump(
    $certificate->getPublicKey(),
);

//$certificate => an instance of SS or CAS Certificate
var_dump(
    $certificate->getPrivateKey(),
);

var_dump(
    $certificate->getPrivateKeyDecrypted() //in case we're working with encrypt_key
);

Generating public and private keys

$pKey = \AdaoPedro\OpenSSLProxy\generateNewPKey();

list($privKey, $pubKey) = \AdaoPedro\OpenSSLProxy\exportKeysFrom($pKey);

echo $pubKey . PHP_EOL;
echo $privKey . PHP_EOL;

Signing

$data = "Hello world!!";

$signature = \AdaoPedro\OpenSSLProxy\getSignatureFrom(
    $data,
    file_get_contents(".../private_key.pem"),
);

Signature verification

$data = "Hello world!!";

echo
\AdaoPedro\OpenSSLProxy\verifySignatureOf(
    $data,
    file_get_contents(".../hash.dat"),
    file_get_contents(".../public_key.pem"),
) === true
? "Verified"
: "Error. Data modified";

Parsing a PHP OpenSSLCertificate certificate object

//$certificate => an instance of SS or CAS Certificate
var_dump(
    $certificate()
);

Checks if a private key corresponds to a certificate

echo
\AdaoPedro\OpenSSLProxy\checkIfPrivateKey(
    file_get_contents(".../private_key.pem")
)->correspondsTo(
    file_get_contents(".../cert.pem")
) === true
? "Yes. It does"
: "No. It does not";

Customizing OpenSSL configurations (in case when we're using certificate generator classes)

use AdaoPedro\OpenSSLProxy\SSCertificate;

//you can find the initial config file in root of lib directory
/*
To customize, just pass the config filename as second parameter to SSCertificate constructor
or third parameter in case of CASCertificate
*/

$certificate = (new SSCertificate(
    days: 365, //expiration
    configFilename: __DIR__ . "/openssl_configs.php"
))->setDistinguishNames(
        //...
);

  Classes of Adão Pedro  >  PHP OpenSSL Proxy  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP OpenSSL Proxy
Base name: php-openssl-proxy
Description: Manage certificates and encrypt data using OpenSSL
Version: 1.0.0
PHP version: 7
License: MIT/X Consortium License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image Utilities and Tools General purpose tools to simplify software development View top rated classes
Group folder image Cryptography Encrypting, decrypting and hashing data View top rated classes
Group folder image PHP 7 Classes using PHP 7 specific features View top rated classes


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imagesrc (9 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file helpers_include.php Aux. Auxiliary script
Accessible without login Plain text file openssl_config.php Aux. Auxiliary script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imagehelpers (4 files)
  Plain text file CASCertificate.php Class Class source
  Plain text file Certificate.php Class Class source
  Plain text file CertificateInterface.php Class Class source
  Plain text file CertificationAutho...ficateInterface.php Class Class source
  Plain text file OpenSSL.php Class Class source
  Plain text file ParsableCertificate.php Class Class source
  Plain text file SaveCertificateInterface.php Class Class source
  Plain text file SelfSignedCertificateInterface.php Class Class source
  Plain text file SSCertificate.php Class Class source

  Files folder image Files  /  src  /  helpers  
File Role Description
  Accessible without login Plain text file fromBase64.php Aux. Auxiliary script
  Accessible without login Plain text file getDateFromTimestamp.php Aux. Auxiliary script
  Accessible without login Plain text file printToFile.php Aux. Auxiliary script
  Accessible without login Plain text file toBase64.php Aux. Auxiliary script

Download Download all files: php-openssl-proxy.tar.gz php-openssl-proxy.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
For more information send a message to info at phpclasses dot org.