PHPackages                             caiquemcz/ssl-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. caiquemcz/ssl-converter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

caiquemcz/ssl-converter
=======================

SSL certificate converter (PEM/DER/PKCS12), CA bundle and private keys in PHP.

v2.0.2(7mo ago)012MITPHPPHP &gt;=7.4CI passing

Since Oct 8Pushed 7mo agoCompare

[ Source](https://github.com/CaiqueMcz/ssl-converter)[ Packagist](https://packagist.org/packages/caiquemcz/ssl-converter)[ RSS](/packages/caiquemcz-ssl-converter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

SSL Converter
=============

[](#ssl-converter)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/204b1791e3a57f86a93de1422b2a6e584f5045431629c5b9abd4e28dbc8b5357/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e342d626c75652e737667)](https://php.net)

A PHP library for converting SSL certificates between different formats (PEM, PFX/PKCS12, JKS), including CA bundles and private keys.

Features
--------

[](#features)

- Convert certificates to PEM format with full chain
- Convert certificates to PFX/PKCS12 format
- Convert certificates to JKS (Java KeyStore) format
- Support for encrypted private keys
- CA bundle handling
- Legacy algorithm support for older systems
- Clean, SOLID architecture
- Fully tested with PHPUnit

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- OpenSSL extension
- Symfony Process component
- Java keytool (for JKS conversion)

Installation
------------

[](#installation)

```
composer require caiquemcz/ssl-converter
```

Usage
-----

[](#usage)

### Quick Start with Fluent API (Recommended)

[](#quick-start-with-fluent-api-recommended)

The simplest way to convert certificates is using the fluent `SslConverter` API:

```
use CaiqueMcz\SslConverter\SslConverter;

// Convert to PEM
$response = (new SslConverter($certificate))
    ->withCaBundle($caBundle)
    ->withPrivateKey($privateKey, $password)  // password is optional
    ->toPem();

// Convert to PFX
$response = (new SslConverter($certificate))
    ->withCaBundle($caBundle)              // optional
    ->withPrivateKey($privateKey, $password)  // password is optional
    ->toPfx('pfx-password', $useLegacy);   // useLegacy is optional (default: false)

// Convert to JKS
$response = (new SslConverter($certificate))
    ->withCaBundle($caBundle)              // optional
    ->withPrivateKey($privateKey, $password)  // password is optional
    ->toJks('jks-password', 'alias', $useLegacy);  // alias and useLegacy are optional

// Save the converted file
file_put_contents(
    $response->virtualFile()->getName(),
    $response->virtualFile()->getContent()
);
```

### Real-World Examples

[](#real-world-examples)

**Example 1: Convert PEM to PFX for Windows servers**

```
use CaiqueMcz\SslConverter\SslConverter;

$certificate = file_get_contents('certificate.pem');
$privateKey = file_get_contents('private.key');
$caBundle = file_get_contents('ca-bundle.pem');

$response = (new SslConverter($certificate))
    ->withCaBundle($caBundle)
    ->withPrivateKey($privateKey)
    ->toPfx('SecurePassword123!');

file_put_contents('certificate.pfx', $response->virtualFile()->getContent());
```

**Example 2: Convert to JKS for Java applications**

```
use CaiqueMcz\SslConverter\SslConverter;

$certificate = file_get_contents('certificate.crt');
$privateKey = file_get_contents('private.key');

$response = (new SslConverter($certificate))
    ->withPrivateKey($privateKey)
    ->toJks('keystore-password', 'myapp');

file_put_contents('keystore.jks', $response->virtualFile()->getContent());
```

**Example 3: Handle encrypted private keys**

```
use CaiqueMcz\SslConverter\SslConverter;

$certificate = file_get_contents('certificate.pem');
$encryptedKey = file_get_contents('encrypted-private.key');

$response = (new SslConverter($certificate))
    ->withPrivateKey($encryptedKey, 'key-encryption-password')
    ->toPfx('pfx-password');

file_put_contents('certificate.pfx', $response->virtualFile()->getContent());
```

**Example 4: Use legacy algorithm for older systems**

```
use CaiqueMcz\SslConverter\SslConverter;

$certificate = file_get_contents('certificate.pem');
$privateKey = file_get_contents('private.key');

$response = (new SslConverter($certificate))
    ->withPrivateKey($privateKey)
    ->toPfx('password', true);  // true = use legacy algorithm

file_put_contents('certificate.pfx', $response->virtualFile()->getContent());
```

### Advanced Usage with Converters

[](#advanced-usage-with-converters)

For more control, use the converter classes directly:

### Converting to PEM Format

[](#converting-to-pem-format)

```
use CaiqueMcz\SslConverter\Converter;
use CaiqueMcz\SslConverter\Formats\PemFormat;
use CaiqueMcz\SslConverter\ValueObjects\CertificateData;
use CaiqueMcz\SslConverter\ValueObjects\PrivateKeyData;

$certificateData = new CertificateData(
    $certificate,
    new PrivateKeyData($privateKey, $privateKeyPassword),
    $caBundle
);

$pemFormat = new PemFormat($certificateData);
$converter = new Converter();

$response = $converter->convert($pemFormat);

// Get the main file (fullchain.pem)
$mainFile = $response->virtualFile();
echo $mainFile->getName();    // fullchain.pem
echo $mainFile->getContent(); // Certificate content

// Get extra files (ca-bundle.pem, private.pem)
foreach ($response->extraVirtualFile() as $file) {
    echo $file->getName();
    echo $file->getContent();
}
```

### Converting to PFX Format

[](#converting-to-pfx-format)

```
use CaiqueMcz\SslConverter\Formats\PfxFormat;

$certificateData = new CertificateData(
    $certificate,
    new PrivateKeyData($privateKey),
    $caBundle
);

$pfxFormat = new PfxFormat($certificateData);
$pfxFormat->setPfxPassword('your-password');

// Optional: Use legacy algorithm for older systems
$pfxFormat->withLegacyAlgorithm();

$converter = new Converter();
$response = $converter->convert($pfxFormat);

$pfxFile = $response->virtualFile();
file_put_contents('certificate.pfx', $pfxFile->getContent());
```

### Converting to JKS Format

[](#converting-to-jks-format)

```
use CaiqueMcz\SslConverter\Formats\JksFormat;

$certificateData = new CertificateData(
    $certificate,
    new PrivateKeyData($privateKey),
    $caBundle
);

$jksFormat = new JksFormat($certificateData);
$jksFormat->setJksPassword('your-password');

// Optional: Use legacy algorithm
$jksFormat->withLegacyAlgorithm();

$converter = new Converter();
$response = $converter->convert($jksFormat);

$jksFile = $response->virtualFile();
file_put_contents('certificate.jks', $jksFile->getContent());
```

### Working with Encrypted Private Keys

[](#working-with-encrypted-private-keys)

```
use CaiqueMcz\SslConverter\ValueObjects\PrivateKeyData;

// Private key with password
$privateKeyData = new PrivateKeyData($privateKey, 'key-password');

$certificateData = new CertificateData(
    $certificate,
    $privateKeyData,
    $caBundle
);

// Use as normal
$pfxFormat = new PfxFormat($certificateData);
$pfxFormat->setPfxPassword('pfx-password');
```

### Getting All Files

[](#getting-all-files)

```
$response = $converter->convert($format);

// Get all files including main and extras
$allFiles = $response->getAllVirtualFiles();

foreach ($allFiles->get() as $file) {
    echo sprintf(
        "File: %s (Size: %d bytes)\n",
        $file->getName(),
        $file->getSize()
    );

    file_put_contents($file->getName(), $file->getContent());
}
```

Format Support
--------------

[](#format-support)

### PEM Format

[](#pem-format)

- Generates `fullchain.pem` (certificate + CA bundle)
- Optional `ca-bundle.pem` (CA certificates)
- Optional `private.pem` (private key)
- Requires CA bundle

### PFX/PKCS12 Format

[](#pfxpkcs12-format)

- Generates `certificate.pfx`
- Requires private key
- Requires password
- Supports legacy algorithm for compatibility
- Optional CA bundle

### JKS Format

[](#jks-format)

- Generates `certificate.jks`
- Requires private key
- Requires password
- Requires Java keytool installed
- Supports legacy algorithm
- Optional CA bundle
- Custom alias support

Architecture
------------

[](#architecture)

The library follows SOLID principles with a clean architecture:

- **Value Objects**: Immutable data containers (`CertificateData`, `PrivateKeyData`, `VirtualFile`)
- **Formats**: Strategy pattern for different certificate formats
- **Generators**: Factory pattern for complex file generation
- **Converters**: Facade for simple API
- **Collections**: Type-safe collections for virtual files

Testing
-------

[](#testing)

```
# Run tests
composer test

# Run tests with coverage
composer test-coverage

# Code style check
composer lint

# Fix code style
composer lint-fix
```

Error Handling
--------------

[](#error-handling)

All conversion errors throw `ConversionException`:

```
use CaiqueMcz\SslConverter\Exceptions\ConversionException;

try {
    $response = $converter->convert($format);
} catch (ConversionException $e) {
    echo "Conversion failed: " . $e->getMessage();
}
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) file for details.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Credits
-------

[](#credits)

Developed by [Caique](https://github.com/caiquemcz)

Support
-------

[](#support)

If you encounter any issues or have questions, please [open an issue](https://github.com/caiquemcz/ssl-converter/issues) on GitHub.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance65

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

215d ago

Major Versions

v1.0.1 → v2.0.02025-10-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a85b28c6350060dcae4877becc90e3dbec324a7f3f981f98eea20c3e42b029f?d=identicon)[Caique1996](/maintainers/Caique1996)

---

Top Contributors

[![CaiqueMcz](https://avatars.githubusercontent.com/u/5604528?v=4)](https://github.com/CaiqueMcz "CaiqueMcz (17 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/caiquemcz-ssl-converter/health.svg)

```
[![Health](https://phpackages.com/badges/caiquemcz-ssl-converter/health.svg)](https://phpackages.com/packages/caiquemcz-ssl-converter)
```

###  Alternatives

[albertoarena/laravel-event-sourcing-generator

Laravel event sourcing domain generator

148.2k](/packages/albertoarena-laravel-event-sourcing-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
