certificatebuilder

Simple Builder API for X509 certificates using Bouncy Castle

License

License

GroupId

GroupId

de.mklinger.commons
ArtifactId

ArtifactId

certificatebuilder
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

certificatebuilder
Simple Builder API for X509 certificates using Bouncy Castle
Project URL

Project URL

https://github.com/de-mklinger/certificatebuilder
Project Organization

Project Organization

mklinger GmbH
Source Code Management

Source Code Management

https://github.com/de-mklinger/certificatebuilder

Download certificatebuilder

How to add to project

<!-- https://jarcasting.com/artifacts/de.mklinger.commons/certificatebuilder/ -->
<dependency>
    <groupId>de.mklinger.commons</groupId>
    <artifactId>certificatebuilder</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.mklinger.commons/certificatebuilder/
implementation 'de.mklinger.commons:certificatebuilder:1.0'
// https://jarcasting.com/artifacts/de.mklinger.commons/certificatebuilder/
implementation ("de.mklinger.commons:certificatebuilder:1.0")
'de.mklinger.commons:certificatebuilder:jar:1.0'
<dependency org="de.mklinger.commons" name="certificatebuilder" rev="1.0">
  <artifact name="certificatebuilder" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.mklinger.commons', module='certificatebuilder', version='1.0')
)
libraryDependencies += "de.mklinger.commons" % "certificatebuilder" % "1.0"
[de.mklinger.commons/certificatebuilder "1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.bouncycastle : bcpkix-jdk15on jar 1.64
de.mklinger.micro : annotations jar 1.0

test (3)

Group / Artifact Type Version
junit : junit jar 4.13
org.hamcrest : hamcrest-library jar 1.3
de.mklinger.micro : keystores jar 1.2

Project Modules

There are no modules declared in this project.

certificatebuilder

Simple Builder API for X.509 certificates using Bouncy Castle.

Usage

Maven dependency:

<dependency>
    <groupId>de.mklinger.commons</groupId>
    <artifactId>certificatebuilder</artifactId>
    <version>1.0</version>
</dependency>

Create a self-signed server certificate:

CertificateAndKeyPair certificateAndKeyPair = new CertificateBuilder()
    .subjectCn("selfsigned-cert")
    .subjectO("My Organization")
    .serverAuth(true)
    .dnsSan("example.org")
    .ipSan("127.0.0.1")
    .validDays(365)
    .keySize(2048)
    .build();

Create CA root certificate, intermediated certificate and signed certificate:

CertificateAndKeyPair root = new CertificateBuilder()
    .subjectCn("ca-root")
    .ca()
    .build();

CertificateAndKeyPair intermediate = new CertificateBuilder()
    .subjectCn("ca-intermediate")
    .ca()
    .validDays(365)
    .issuer(root)
    .build();

CertificateAndKeyPair cert = new CertificateBuilder()
    .subjectCn("cert")
    .validDays(365)
    .issuer(intermediate)
    .serverAuth(true)
    .dnsSan("example.org")
    .ipSan("127.0.0.1")
    .build();

PrivateKey privateKey = certificateAndKeyPair.getKeyPair().getPrivate();

Certificate[] certificateChain = {
    cert.getCertificate(),
    intermediate.getCertificate(),
    root.getCertificate()
};
de.mklinger.commons

mklinger GmbH

Versions

Version
1.0