public final class CertUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static void | exportCert(Certificate cert,
OutputStream out)Modified from:
http://www.exampledepot.com/egs/java.security.cert/ExportCert.html
Writes a certificate in base64 format. |
static void | exportCRL(X509CRL crl,
OutputStream out)Writes a CRL in base64 format. |
static void | exportPrivateKey(PrivateKey pk,
Certificate[] certs,
OutputStream out)Writes the private key and all certs in base64 format. |
static String | getIssuerValue(X509Certificate cert,
String type)Get a value out of the issuer distinguished name. |
static Set<String> | getSubjectAlternativeNames(X509Certificate cert)Get the set of Subject Alternative Names, including
DNSNames, RFC822Names, IPv4 and v6 addresses as strings. |
static String | getSubjectValue(X509Certificate cert,
String type)Get a value out of the subject distinguished name. |
static boolean | isRevoked(Certificate cert)Is the certificate revoked?
This loads the CRLs from disk. |
static boolean | isRevoked(CertStore store,
Certificate cert)Is the certificate revoked? |
static boolean | isRevoked(I2PAppContext ctx,
Certificate cert)Is the certificate revoked?
This loads the CRLs from disk. |
static X509Certificate | loadCert(File kd)Get the certificate from a X.509 certificate file. |
static List<X509Certificate> | loadCerts(InputStream in)Get one or more certificates from an input stream. |
static X509CRL | loadCRL(InputStream in)Load a CRL. |
static CertStore | loadCRLs()Load CRLs from standard locations. |
static CertStore | loadCRLs(I2PAppContext ctx)Load CRLs from standard locations. |
static PublicKey | loadKey(File kd)Get the Java public key from a X.509 certificate file. |
static PrivateKey | loadPrivateKey(InputStream in)Get a single Private Key from an input stream. |
static void | main(String[] args)For testing purposes. |
static boolean | saveCert(Certificate cert,
File file)Write a certificate to a file in base64 format. |
static boolean | saveCRL(X509CRL crl,
File file)Write a CRL to a file in base64 format. |
public static void exportCert(Certificate cert, OutputStream out) throws IOException, CertificateEncodingException
cert - the certificate to exportout - the output stream to write toIOException - if the write failsCertificateEncodingException - if the certificate cannot be encodedpublic static void exportCRL(X509CRL crl, OutputStream out) throws IOException, CRLException
crl - the CRL to exportout - the output stream to write toIOException - if the write failsCRLException - if the crl does not support encodingpublic static void exportPrivateKey(PrivateKey pk, Certificate[] certs, OutputStream out) throws IOException, GeneralSecurityException
pk - non-nullcerts - certificate chain, null or empty to export pk onlyout - the output stream to write toInvalidKeyException - if the key does not support encodingCertificateEncodingException - if a cert does not support encodingIOException - if the write failsGeneralSecurityException - on any other security errorpublic static String getIssuerValue(X509Certificate cert, String type)
cert - the certificatetype - e.g. "CN"public static Set<String> getSubjectAlternativeNames(X509Certificate cert)
cert - the certificate to extract names frompublic static String getSubjectValue(X509Certificate cert, String type)
cert - the certificatetype - e.g. "CN"public static boolean isRevoked(Certificate cert)
cert - the certificate to checkpublic static boolean isRevoked(CertStore store, Certificate cert)
store - the cert store containing CRLscert - the certificate to checkpublic static boolean isRevoked(I2PAppContext ctx, Certificate cert)
ctx - the contextcert - the certificate to checkpublic static X509Certificate loadCert(File kd) throws IOException, GeneralSecurityException
kd - the certificate fileIOException - if the file cannot be readGeneralSecurityException - if the certificate is invalidpublic static List<X509Certificate> loadCerts(InputStream in) throws IOException, GeneralSecurityException
in - the input stream to read fromIOException - if the read failsGeneralSecurityException - if any certificate is invalidpublic static X509CRL loadCRL(InputStream in) throws GeneralSecurityException
in - the input stream to read fromGeneralSecurityException - if the CRL cannot be loadedpublic static CertStore loadCRLs()
public static CertStore loadCRLs(I2PAppContext ctx)
ctx - the application contextpublic static PublicKey loadKey(File kd) throws IOException, GeneralSecurityException
kd - the certificate fileIOException - if the file cannot be readGeneralSecurityException - if the certificate is invalidpublic static PrivateKey loadPrivateKey(InputStream in) throws IOException, GeneralSecurityException
in - the input stream to read fromIOException - if the read failsGeneralSecurityException - if the key is invalidpublic static final void main(String[] args)
args - command-line argumentspublic static boolean saveCert(Certificate cert, File file)
cert - the certificate to savefile - the file to write to