public class PKIUtils extends Object
| Constructor and Description |
|---|
PKIUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkIssued(X509Certificate issuer,
X509Certificate issued)
Checks if a certificate issued another certificate, according to RFC 3280.
|
static boolean |
DNCompare(String dn1,
String dn2) |
static org.bouncycastle.asn1.x509.AuthorityKeyIdentifier |
getAKID(X509Certificate cert)
Gets the AuthorityKeyIdentifier extension form the passed certificate.
|
static String |
getBaseName(File f)
Gets the basename of a file.
|
static org.bouncycastle.asn1.x509.BasicConstraints |
getBasicConstraints(X509Certificate cert)
Gets the BasicConstraints extension form the passed certificate.
|
static String |
getHash(byte[] name)
Gets the MD5 hash value of the given byte array.
|
static String |
getHash(X500Principal principal)
Gets the MD5 hash value of the given principal.
|
static String |
getHash(X509Certificate x509)
Gets the MD5 hash value of the subject of the given certificate.
|
static String |
getHash(X509CRL crl)
Gets the MD5 hash value of the issuer of the given CRL.
|
static String |
getHash(org.bouncycastle.jce.X509Principal principal)
Gets the MD5 hash value of the given principal.
|
static String |
getOpenSSLFormatPrincipal(Principal principal) |
static String |
getOpenSSLFormatPrincipal(Principal principal,
boolean reverse)
Gets an OpenSSL-style representation of a principal.
|
static org.bouncycastle.asn1.x509.SubjectKeyIdentifier |
getSKID(X509Certificate cert)
Gets the SubjectKeyIdentifier extension form the passed certificate.
|
static boolean |
isCA(X509Certificate cert)
Checks if the passed certificate is a CA certificate.
|
static boolean |
isProxy(X509Certificate cert)
Checks if the passed certificate is a proxy certificate.
|
static X509Certificate[] |
loadCertificates(File file)
Loads a set of credentials from a file.
|
static X509Certificate[] |
loadCertificates(String filename)
Loads a set of credentials from a file.
|
static X509CRL |
loadCRL(File file)
Loads a CRL from a file.
|
static X509CRL |
loadCRL(String filename)
Loads a CRL from a file.
|
static PrivateKey |
loadPrivateKey(File file,
org.bouncycastle.openssl.PasswordFinder finder) |
static PrivateKey |
loadPrivateKey(String filename,
org.bouncycastle.openssl.PasswordFinder finder) |
static String |
Normalize(String dn)
Compares two DNs for equality, taking into account different
representations for the Email and UserID tags.
|
static Object |
readObject(File f)
Reads either a certificate or a CRL from a file.
|
static boolean |
selfIssued(X509Certificate cert)
Checks if the give certificate is self-issued.
|
static int |
skipToCertBeginning(BufferedInputStream stream)
Prepares a BufferedInputStream to read either a certificate or a CRL
from it.
|
public static String getHash(X509Certificate x509)
x509 - The certificate from which to get the subject.IllegalArgumentException - if x509 is null.InvalidStateException - if the MD5 algorithm is not supported.public static String getHash(X509CRL crl)
crl - The CRL from which to get the issuer.IllegalArgumentException - if crl is null.InvalidStateException - if the MD5 algorithm is not supported.public static String getHash(org.bouncycastle.jce.X509Principal principal)
principal - the principal.IllegalArgumentException - if crl is null.InvalidStateException - if the MD5 algorithm is not supported.public static String getHash(X500Principal principal)
principal - the principal.IllegalArgumentException - if crl is null.InvalidStateException - if the MD5 algorithm is not supported.public static String getHash(byte[] name)
name - the data from which to compute the hash.IllegalArgumentException - if crl is null.InvalidStateException - if the MD5 algorithm is not supported.public static String getOpenSSLFormatPrincipal(Principal principal, boolean reverse)
principal - the principalpublic static String Normalize(String dn)
dn1 - the first dn to compare.dn2 - the second dn to comparepublic static String getBaseName(File f)
f - File object representing a file.public static boolean selfIssued(X509Certificate cert)
cert - The certificate to check.public static boolean checkIssued(X509Certificate issuer, X509Certificate issued)
issuer - The candidate issuer certificate.issued - The candidate issued certificate.public static boolean isCA(X509Certificate cert)
cert - the candidate CA certificate.public static boolean isProxy(X509Certificate cert)
cert - the candidate proxy certificate.public static org.bouncycastle.asn1.x509.AuthorityKeyIdentifier getAKID(X509Certificate cert)
cert - The certificate from which to get the extension.public static org.bouncycastle.asn1.x509.SubjectKeyIdentifier getSKID(X509Certificate cert)
cert - The certificate from which to get the extension.public static org.bouncycastle.asn1.x509.BasicConstraints getBasicConstraints(X509Certificate cert)
cert - The certificate from which to get the extension.public static PrivateKey loadPrivateKey(String filename, org.bouncycastle.openssl.PasswordFinder finder)
public static PrivateKey loadPrivateKey(File file, org.bouncycastle.openssl.PasswordFinder finder)
public static X509Certificate[] loadCertificates(String filename) throws CertificateException
filename - the name of the file from which to load the certificates.CertificateException - if there were problems parsing the certificates.IllegalArgumentException - if the file cannot be found.public static X509Certificate[] loadCertificates(File file) throws CertificateException
file - the File object from which to load the certificates.CertificateException - if there were problems parsing the certificates.IllegalArgumentException - if the file cannot be found.Filepublic static X509CRL loadCRL(String filename) throws CRLException
filename - the name of the file from which to load the CRL.CRLException - if there were problems parsing the CRL.IllegalArgumentException - if the file cannot be found.public static X509CRL loadCRL(File file) throws CRLException
file - the File object from which to load the CRL.CRLException - if there were problems parsing the CRL.IllegalArgumentException - if the file cannot be found.public static Object readObject(File f) throws IOException, CertificateException, CRLException
f - the file from which to read;IOException - if there have been problems reading the file.CertificateException - if there have been problems parsing the certificate.CRLException - if there have been problems parsing the CRL.public static int skipToCertBeginning(BufferedInputStream stream) throws IOException
stream - The stream to read and skip.IOException - Thrown if there is a problem skipping.
Note: this a modified version of code originally written by Joni HakhalaCopyright © 2014. All rights reserved.