use of org.spongycastle.asn1.x500.X500NameBuilder in project bnd by bndtools.
the class Server method createSelfSignedCertifcate.
private X509Certificate[] createSelfSignedCertifcate(KeyPair keyPair) throws Exception {
X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
nameBuilder.addRDN(BCStyle.CN, "localhost");
Date notBefore = new Date();
Date notAfter = new Date(System.currentTimeMillis() + 24 * 3 * 60 * 60 * 1000);
BigInteger serialNumber = new BigInteger(128, random);
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(nameBuilder.build(), serialNumber, notBefore, notAfter, nameBuilder.build(), keyPair.getPublic());
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(keyPair.getPrivate());
X509Certificate certificate = new JcaX509CertificateConverter().getCertificate(certificateBuilder.build(contentSigner));
return new X509Certificate[] { certificate };
}
Aggregations