public class CertificateHandler extends Object
| Constructor and Description |
|---|
CertificateHandler() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
createOutputKeystore(String type,
String alias,
String password,
PrivateKey privateKey,
X509Certificate certificate)
Place a cert/key in a PKCS12 or JKS keystore
|
static X509Certificate |
getCertFromNginxHeader(String certificateHeader)
Extract a certificate from a nginx header containing a PEM formatet certificate
|
static X509Certificate |
getCertFromPem(String pemCertificate)
Converts a PEM encoded certificate to a X509Certificate
|
static String |
getElement(org.bouncycastle.asn1.x500.X500Name x500name,
org.bouncycastle.asn1.ASN1ObjectIdentifier objectId)
Extract a value from the DN extracted from a certificate
|
static PKIIdentity |
getIdentityFromCert(X509Certificate userCertificate)
Extracts a PKIIdentity from a certificate using the MC PKI certificate "format"
|
static String |
getPemFromEncoded(String type,
byte[] encoded)
Convert a cert/key to pem from "encoded" format (byte[])
|
static boolean |
verifyCertificate(PublicKey verificationPubKey,
X509Certificate certToVerify,
Date verificationDate)
Verify a single certificate against the public key of the issueing certificate.
|
static boolean |
verifyCertificateChain(X509Certificate certificate,
KeyStore ks)
Verify a single certificate against trust chain in the keystore.
|
public static boolean verifyCertificate(PublicKey verificationPubKey, X509Certificate certToVerify, Date verificationDate)
verifyCertificateChain instead to verify the
complete chain.verificationPubKey - Public key of the issuing certificatecertToVerify - The certificate to verifyverificationDate - Date the certificate must be valid. If null the present day is used.public static boolean verifyCertificateChain(X509Certificate certificate, KeyStore ks) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, InvalidAlgorithmParameterException, CertPathValidatorException
certificate - The certificate to verifyks - The truststore that contains the trust chainKeyStoreException - Thrown if keystore loading failsNoSuchAlgorithmException - Thrown if PKIX initialization failsCertificateException - Thrown if certificate cannot be loadedInvalidAlgorithmParameterException - Thrown if keystore loading failsCertPathValidatorException - Thrown if certificate is invalid.public static String getPemFromEncoded(String type, byte[] encoded)
type - The type, currently "CERTIFICATE", "PUBLIC KEY", "PRIVATE KEY" or "X509 CRL" are usedencoded - The encoded byte[]public static byte[] createOutputKeystore(String type, String alias, String password, PrivateKey privateKey, X509Certificate certificate)
type - The keystore type to use (PKCS12 or JKS)alias - The alias of the certificate in the keystorepassword - The password used to protect the keyprivateKey - Private key of the certificatecertificate - The certificatepublic static X509Certificate getCertFromNginxHeader(String certificateHeader)
certificateHeader - The header containing the certificatepublic static X509Certificate getCertFromPem(String pemCertificate)
pemCertificate - String containing the PEM encoded certificatepublic static PKIIdentity getIdentityFromCert(X509Certificate userCertificate)
userCertificate - The certificatepublic static String getElement(org.bouncycastle.asn1.x500.X500Name x500name, org.bouncycastle.asn1.ASN1ObjectIdentifier objectId)
x500name - The full DN from certificateobjectId - The Identifier to findCopyright © 2012–2019 Danish Maritime Authority. All rights reserved.