use of org.bouncycastle.jcajce.provider.asymmetric.edec.BCEdDSAPublicKey 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 org.bouncycastle.jcajce.provider.asymmetric.edec.BCEdDSAPublicKey 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 org.bouncycastle.jcajce.provider.asymmetric.edec.BCEdDSAPublicKey in project jans by JanssenProject.
the class EDDSASigner method validateSignature.
/**
* Validating a signature.
*/
@Override
public boolean validateSignature(String signingInput, String signature) throws SignatureException {
SignatureAlgorithm signatureAlgorithm = getSignatureAlgorithm();
if (signatureAlgorithm == null) {
throw new SignatureException("The signature algorithm is null");
}
if (!signatureAlgorithm.getFamily().equals(AlgorithmFamily.ED)) {
throw new SignatureException(String.format("Wrong value of the signature algorithm: %s", signatureAlgorithm.getFamily().toString()));
}
if (eddsaPublicKey == null) {
throw new SignatureException("The EDDSA public key is null");
}
if (signingInput == null) {
throw new SignatureException("The signing input is null");
}
try {
X509EncodedKeySpec publicKeySpec = eddsaPublicKey.getPublicKeySpec();
java.security.KeyFactory keyFactory = java.security.KeyFactory.getInstance(signatureAlgorithm.getName());
BCEdDSAPublicKey publicKey = (BCEdDSAPublicKey) keyFactory.generatePublic(publicKeySpec);
Signature virifier = Signature.getInstance(signatureAlgorithm.getName(), "BC");
virifier.initVerify(publicKey);
virifier.update(signingInput.getBytes());
return virifier.verify(Base64Util.base64urldecode(signature));
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException | InvalidKeyException | IllegalArgumentException e) {
throw new SignatureException(e);
}
}
use of org.bouncycastle.jcajce.provider.asymmetric.edec.BCEdDSAPublicKey in project jans by JanssenProject.
the class Certificate method getPublicKey.
/**
* Returns Public Key from X509 Certificate.
*
* @return Public Key from X509 Certificate.
*/
public PublicKey getPublicKey() {
if (x509Certificate == null) {
return null;
}
PublicKey publicKey = null;
if (x509Certificate.getPublicKey() instanceof BCRSAPublicKey) {
BCRSAPublicKey jcersaPublicKey = (BCRSAPublicKey) x509Certificate.getPublicKey();
publicKey = new RSAPublicKey(jcersaPublicKey.getModulus(), jcersaPublicKey.getPublicExponent());
} else if (x509Certificate.getPublicKey() instanceof BCECPublicKey) {
BCECPublicKey jceecPublicKey = (BCECPublicKey) x509Certificate.getPublicKey();
publicKey = new ECDSAPublicKey(signatureAlgorithm, jceecPublicKey.getQ().getXCoord().toBigInteger(), jceecPublicKey.getQ().getYCoord().toBigInteger());
} else if (x509Certificate.getPublicKey() instanceof BCEdDSAPublicKey) {
BCEdDSAPublicKey jceedPublicKey = (BCEdDSAPublicKey) x509Certificate.getPublicKey();
publicKey = new EDDSAPublicKey(signatureAlgorithm, jceedPublicKey.getEncoded());
}
return publicKey;
}
use of org.bouncycastle.jcajce.provider.asymmetric.edec.BCEdDSAPublicKey in project jans by JanssenProject.
the class Certificate method getEddsaPublicKey.
/**
* Returns EDDSA Public Key from X509 Certificate.
*
* @return EDDSA Public Key from X509 Certificate.
*/
public EDDSAPublicKey getEddsaPublicKey() {
EDDSAPublicKey eddsaPublicKey = null;
if (x509Certificate != null && x509Certificate.getPublicKey() instanceof BCEdDSAPublicKey) {
BCEdDSAPublicKey publicKey = (BCEdDSAPublicKey) x509Certificate.getPublicKey();
eddsaPublicKey = new EDDSAPublicKey(signatureAlgorithm, publicKey.getEncoded());
}
return eddsaPublicKey;
}
Aggregations