PHPackages                             vdhicts/laravel-csr-generator - 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. vdhicts/laravel-csr-generator

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

vdhicts/laravel-csr-generator
=============================

Easily generate a CSR with Laravel.

v3.1.0(2mo ago)56.6k↓45%MITPHPPHP &gt;=8.1CI passing

Since Sep 21Pushed 2mo agoCompare

[ Source](https://github.com/vdhicts/csr-generator)[ Packagist](https://packagist.org/packages/vdhicts/laravel-csr-generator)[ Docs](https://github.com/vdhicts/laravel-csr-generator)[ RSS](/packages/vdhicts-laravel-csr-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (12)Versions (9)Used By (0)

CSR generator
=============

[](#csr-generator)

PHP offers several methods to help generate a CSR and private key. Unfortunately, some CSR parts (i.e. subject alternative names) are not easily usable. This Laravel package aims to make the procedure easier within your Laravel application.

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

[](#requirements)

This Laravel package requires PHP 8.1 or higher, Laravel 9+ and you will need the openssl extension as that's required for the `openssl_*` php functions used by this package.

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

[](#installation)

This package can be used in any Laravel project.

You can install the package via composer:

`composer require vdhicts/laravel-csr-generator`

Usage
-----

[](#usage)

This package is an easy-to-use wrapper around the PHP functions.

### Getting started

[](#getting-started)

All steps can be performed individually to suit all your needs.

```
// Generate the private key
$privateKey = (new PrivateKeyGenerator())->generate();

// Collect the subject fields
$subjectFields = new SubjectFields(
    'example.com',
    'security@example.com',
    'NL',
    'Zuid-Holland',
    'Den Haag',
    'Example',
    'DevOps',
    ['www.example.com']
);

// Generate the csr
$csr = (new CsrGenerator($subjectFields, $privateKey))->generate();
$csrContent = $csr->export();
```

### Generate private key

[](#generate-private-key)

The private key can be generated with the `PrivateKeyGenerator`. It's possible to manually determine the key bits and type. Additional options can be provided too. The generator will return null when failed or an instance of `PrivateKey`.

```
$privateKey = (new PrivateKeyGenerator())
    ->setPrivateKeyBits(8196)
    ->setPrivateKeyType(OPENSSL_KEYTYPE_RSA)
    ->setAdditionalOptions(['config' => 'your-config-file'])
    ->generate();
```

You can access the `OpenSSLAsymmetricKey` as a property.

### Export private key as string

[](#export-private-key-as-string)

To convert the private key to a string, use the `export` method on the `PrivateKey` object or cast the object to a string:

#### Encrypted key

[](#encrypted-key)

```
$privateKeyContent = $privateKey
    ->setPassPhrase('test-1234!')
    //->setAdditionalOptions(['config' => 'path-to-your-config-file'])
    ->export();
```

#### Unencrypted key

[](#unencrypted-key)

```
$privateKeyContent = $privateKey
    ->setPassPhrase(null)
    //->setAdditionalOptions(['config' => 'path-to-your-config-file'])
    ->export();
```

When you don't set the passphrase or set it to `null`, the key won't be encrypted.

### Generate CSR

[](#generate-csr)

To generate the CSR, generate the private key and create the subject fields first. The generator will return null when failed or an instance of `Csr`.

```
$subjectFields = new SubjectFields(
    'example.com',
    'security@example.com',
    'NL',
    'Zuid-Holland',
    'Den Haag',
    'Example',
    'DevOps',
    ['www.example.com']
);
$csr = (new CsrGenerator($subjectFields, $privateKey))
    ->setAdditionalOptions(['config' => 'path-to-your-config-file'])
    ->generate();
```

You can access the `OpenSSLCertificateSigningRequest` as a property.

#### Subject alternative names &amp; your own config

[](#subject-alternative-names--your-own-config)

When providing subject alternative names, the config file from the additional options will be **overwritten**. This is required to provide the subject alternative names as those can't be provided directly to the `openssl_` functions built in PHP. If you need to provide subject alternative names and a custom config, leave the subject alternative names in the `SubjectFields` empty and provide your config with the SAN section:

```
$subjectFields = new SubjectFields(
    'example.com',
    'security@example.com',
    'NL',
    'Zuid-Holland',
    'Den Haag',
    'Example',
    'DevOps' // so not providing the subject alternative names here
);

// Create your config file with the subject alternative names
..

// Provide your config file to the generator
$csr = (new CsrGenerator($subjectFields, $privateKey))
    ->setAdditionalOptions(['config' => 'path-to-your-config-file'])
    ->generate();
```

To help you create the config file, it's possible to publish the view for the config file. This view is used by default for generating the config with the subject alternative names.

```
php artisan vendor:publish --provider="Vdhicts\CsrGenerator\CsrGeneratorServiceProvider" --tag=csr-generator-views

```

### Export CSR as string

[](#export-csr-as-string)

To convert the CSR to a string, use the `export` method on the `Csr` object or cast the object to a string:

```
$csrContent = $csr->export();
```

### Custom configuration

[](#custom-configuration)

Some defaults are set which are used by the generators. To change those defaults, publish the configuration file with:

```
php artisan vendor:publish --provider="Vdhicts\CsrGenerator\CsrGeneratorServiceProvider" --tag=csr-generator-config

```

Tests
-----

[](#tests)

Unit tests are available in the `tests` folder. Run with:

`composer test`

When you want a code coverage report which will be generated in the `build/report` folder. Run with:

`composer test-coverage`

Contribution
------------

[](#contribution)

Any contribution is welcome, see the [Contributing guidelines](CONTRIBUTING.md).

Security
--------

[](#security)

If you discover any security-related issues in this or other packages of Vdhicts, please email instead of using the issue tracker.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

About Vdhicts
-------------

[](#about-vdhicts)

[Vdhicts](https://www.vdhicts.nl) is the name of my company for which I work as a freelancer. Vdhicts develops and implements IT solutions for businesses and educational institutions.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance88

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~212 days

Recently: every ~183 days

Total

7

Last Release

61d ago

Major Versions

v1.0.0 → v2.0.02023-03-23

v2.3.0 → v3.0.02025-03-01

PHP version history (2 changes)v1.0.0PHP ^8.1

v2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/88d23e7b707d1cfe0eea91c00590613f45e0c75cb0a3ce89354328332e5c0c02?d=identicon)[vdhicts](/maintainers/vdhicts)

---

Top Contributors

[![dvdheiden](https://avatars.githubusercontent.com/u/90568118?v=4)](https://github.com/dvdheiden "dvdheiden (9 commits)")

---

Tags

csrgeneratorlaravelphpgeneratorcsrvdhicts

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vdhicts-laravel-csr-generator/health.svg)

```
[![Health](https://phpackages.com/badges/vdhicts-laravel-csr-generator/health.svg)](https://phpackages.com/packages/vdhicts-laravel-csr-generator)
```

###  Alternatives

[lara-zeus/popover

Zeus Popover is filamentphp component to show a Popover with custom content in tables and infolist

2968.2k3](/packages/lara-zeus-popover)[lara-zeus/inline-chart

Zeus Inline Chart easily add a chart in filamentPHP table column

2139.9k](/packages/lara-zeus-inline-chart)[lara-zeus/quantity

filamentphp Input Number component, with user-friendly increment and decrement controls

2065.8k3](/packages/lara-zeus-quantity)[lara-zeus/accordion

Zeus Accordion is filamentphp layout component to group components

11122.8k2](/packages/lara-zeus-accordion)[luilliarcec/laravel-username-generator

Laravel Username Generator is a package that allows the versatile generation of user names, has a simple integration with Laravel.

1011.8k](/packages/luilliarcec-laravel-username-generator)

PHPackages © 2026

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