PHP code example of exonet / certificate-converter

1. Go to this page and download the library: Download exonet/certificate-converter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

exonet / certificate-converter example snippets


// Initialise a new certificate converter.
$converter = new Converter();

// Setup the plain format class that should be converted.
$plain = new Plain();
$plain
    ->setKey('-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
')
    ->setCrt('-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
')
    ->setCaBundle('-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
');

// Convert the plain certificate to PEM.
$pem = $converter
    ->from($plain)
    ->to(new Pem());

// Save as zip file.
$pem->asZip('./');

// Get an array with the certificate files:
print_r($pem->asFiles());

// Get the certificate as string:
print_r($pem->asString());