use of io.jans.as.model.crypto.Certificate in project jans by JanssenProject.
the class ECDSAKeyFactory method generateV3Certificate.
public Certificate generateV3Certificate(Date startDate, Date expirationDate, String dnName) throws OperatorCreationException, CertificateException {
// Create certificate
Certificate resCertificate = null;
BCEdDSAPublicKey publicKey = (BCEdDSAPublicKey) keyPair.getPublic();
// serial number for certificate
BigInteger serialNumber = new BigInteger(1024, new SecureRandom());
X500Name name = new X500Name(dnName);
JcaX509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(name, serialNumber, startDate, expirationDate, name, publicKey);
X509CertificateHolder certHolder = certGen.build(new JcaContentSignerBuilder(signatureAlgorithm.getAlgorithm()).setProvider(DEF_BC).build(keyPair.getPrivate()));
X509Certificate cert = new JcaX509CertificateConverter().setProvider(DEF_BC).getCertificate(certHolder);
resCertificate = new Certificate(signatureAlgorithm, cert);
return resCertificate;
}
use of io.jans.as.model.crypto.Certificate in project jans by JanssenProject.
the class EDDSAKeyFactory method generateV3Certificate.
/**
* Generates certificate X509 v3
*
* @param startDate
* @param expirationDate
* @param dnName
* @return
* @throws CertificateEncodingException
* @throws InvalidKeyException
* @throws IllegalStateException
* @throws NoSuchProviderException
* @throws NoSuchAlgorithmException
* @throws SignatureException
*/
public Certificate generateV3Certificate(final Date startDate, final Date expirationDate, final String dnName) throws SignatureException {
// Creating the certificate
Certificate resCertificate = null;
try {
BCEdDSAPublicKey publicKey = (BCEdDSAPublicKey) keyPair.getPublic();
// serial number for certificate
BigInteger serialNumber = new BigInteger(1024, new SecureRandom());
X500Name name = new X500Name(dnName);
JcaX509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(name, serialNumber, startDate, expirationDate, name, publicKey);
X509CertificateHolder certHolder = certGen.build(new JcaContentSignerBuilder(signatureAlgorithm.getAlgorithm()).setProvider(DEF_BC).build(keyPair.getPrivate()));
X509Certificate cert = new JcaX509CertificateConverter().setProvider(DEF_BC).getCertificate(certHolder);
resCertificate = new Certificate(signatureAlgorithm, cert);
} catch (Exception e) {
throw new SignatureException(e);
}
return resCertificate;
}
use of io.jans.as.model.crypto.Certificate in project jans by JanssenProject.
the class SignatureTest method generateES256Keys.
@Test
public void generateES256Keys() throws Exception {
showTitle("TEST: generateES256Keys");
KeyFactory<ECDSAPrivateKey, ECDSAPublicKey> keyFactory = new ECDSAKeyFactory(SignatureAlgorithm.ES256, "CN=Test CA Certificate");
Key<ECDSAPrivateKey, ECDSAPublicKey> key = keyFactory.getKey();
ECDSAPrivateKey privateKey = key.getPrivateKey();
ECDSAPublicKey publicKey = key.getPublicKey();
Certificate certificate = key.getCertificate();
System.out.println(key);
String signingInput = "Hello World!";
ECDSASigner ecdsaSigner1 = new ECDSASigner(SignatureAlgorithm.ES256, privateKey);
String signature = ecdsaSigner1.generateSignature(signingInput);
ECDSASigner ecdsaSigner2 = new ECDSASigner(SignatureAlgorithm.ES256, publicKey);
assertTrue(ecdsaSigner2.validateSignature(signingInput, signature));
ECDSASigner ecdsaSigner3 = new ECDSASigner(SignatureAlgorithm.ES256, certificate);
assertTrue(ecdsaSigner3.validateSignature(signingInput, signature));
}
use of io.jans.as.model.crypto.Certificate in project jans by JanssenProject.
the class SignatureTest method generateRS384Keys.
@Test
public void generateRS384Keys() throws Exception {
showTitle("TEST: generateRS384Keys");
KeyFactory<RSAPrivateKey, RSAPublicKey> keyFactory = new RSAKeyFactory(SignatureAlgorithm.RS384, "CN=Test CA Certificate");
Key<RSAPrivateKey, RSAPublicKey> key = keyFactory.getKey();
RSAPrivateKey privateKey = key.getPrivateKey();
RSAPublicKey publicKey = key.getPublicKey();
Certificate certificate = key.getCertificate();
System.out.println(key);
String signingInput = "Hello World!";
RSASigner rsaSigner1 = new RSASigner(SignatureAlgorithm.RS384, privateKey);
String signature = rsaSigner1.generateSignature(signingInput);
RSASigner rsaSigner2 = new RSASigner(SignatureAlgorithm.RS384, publicKey);
assertTrue(rsaSigner2.validateSignature(signingInput, signature));
RSASigner rsaSigner3 = new RSASigner(SignatureAlgorithm.RS384, certificate);
assertTrue(rsaSigner3.validateSignature(signingInput, signature));
}
use of io.jans.as.model.crypto.Certificate in project jans by JanssenProject.
the class SignatureTest method generateRS256Keys.
@Test
public void generateRS256Keys() throws Exception {
showTitle("TEST: generateRS256Keys");
KeyFactory<RSAPrivateKey, RSAPublicKey> keyFactory = new RSAKeyFactory(SignatureAlgorithm.RS256, "CN=Test CA Certificate");
Key<RSAPrivateKey, RSAPublicKey> key = keyFactory.getKey();
RSAPrivateKey privateKey = key.getPrivateKey();
RSAPublicKey publicKey = key.getPublicKey();
Certificate certificate = key.getCertificate();
System.out.println(key);
String signingInput = "Hello World!";
RSASigner rsaSigner1 = new RSASigner(SignatureAlgorithm.RS256, privateKey);
String signature = rsaSigner1.generateSignature(signingInput);
RSASigner rsaSigner2 = new RSASigner(SignatureAlgorithm.RS256, publicKey);
assertTrue(rsaSigner2.validateSignature(signingInput, signature));
RSASigner rsaSigner3 = new RSASigner(SignatureAlgorithm.RS256, certificate);
assertTrue(rsaSigner3.validateSignature(signingInput, signature));
}
Aggregations