public class CertUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CertUtils.CertContainer |
| Constructor and Description |
|---|
CertUtils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
certAndWrappedKeyToRawByteFormat(byte[] wrappedKey,
X509Certificate cert) |
X509Certificate |
certFromFile(String certFile)
Creates an X509Certificate object from an existing file.
|
static byte[] |
changePkcs12Protection(byte[] bytes,
char[] oldKeyStorePassPhrase,
char[] oldPrivateKeyPassPhrase,
char[] newKeystorePassPhrase,
char[] newPrivateKeyPassPhrase)
Modifies the keystore and private key protection on a PKCS12 keystore.
|
static String |
getJCEProviderName()
Gets the configured JCE crypto provider string for crypto operations.
|
static String |
getOwner(X509Certificate certificate)
Gets the owner of the certificate with is the email address of domain bound to the certificate.
|
protected static boolean |
isByteDataWrappedKeyPair(byte[] data) |
static byte[] |
pkcs12ToStrippedPkcs12(byte[] bytes,
String passphrase)
Takes a PKCS12 byte stream and returns a PKCS12 byte stream with the pass phrase protection and encryption removed.
|
static void |
setJCEProviderName(String name)
Overrides the configured JCE crypto provider string.
|
static CertUtils.CertContainer |
toCertContainer(byte[] data)
Converts a raw byte array that is in the Certificate data store format to a CertContainer.
|
static CertUtils.CertContainer |
toCertContainer(byte[] data,
boolean loadPrivateKey) |
static CertUtils.CertContainer |
toCertContainer(byte[] data,
char[] keyStorePassPhrase,
char[] privateKeyPassPhrase) |
static CertUtils.CertContainer |
toCertContainer(byte[] data,
char[] keyStorePassPhrase,
char[] privateKeyPassPhrase,
boolean loadPrivateKey)
Creates a certificate container that consists of the X509 certificate and its private key (if it exists).
|
static X509Certificate |
toX509Certificate(byte[] data)
Converts a byte stream to an X509Certificate.
|
static X509Certificate |
toX509Certificate(byte[] data,
String passPhrase)
Converts a byte stream to an X509Certificate.
|
public static String getJCEProviderName()
public static void setJCEProviderName(String name)
name - The name of the JCE provider.public static String getOwner(X509Certificate certificate)
certificate - The certificate of the to get the owner of.public static byte[] pkcs12ToStrippedPkcs12(byte[] bytes,
String passphrase)
bytes - The PKCS12 byte stream that will be stripped.passphrase - The pass phrase of the PKCS12 byte stream. This is used to decrypt the PKCS12 stream.public static byte[] changePkcs12Protection(byte[] bytes,
char[] oldKeyStorePassPhrase,
char[] oldPrivateKeyPassPhrase,
char[] newKeystorePassPhrase,
char[] newPrivateKeyPassPhrase)
bytes - The PKCS12 encoded as byte array that will be modified.oldKeyStorePassPhrase - The current pass phrase protecting the keystore file.oldPrivateKeyPassPhrase - The current pass phrase protecting the private key.newKeystorePassPhrase - The new pass phrase protecting the keystore file.newPrivateKeyPassPhrase - The new pass phrase protecting the private key.public static X509Certificate toX509Certificate(byte[] data)
If the stream is a PKCS12 representation, then an empty ("") pass phrase is used to decrypt the stream. In addition the resulting X509Certificate implementation will contain the private key.
data - The byte stream representation to convert.public static X509Certificate toX509Certificate(byte[] data, String passPhrase)
If the stream is a PKCS12 representation, then the pass phrase is used to decrypt the stream. In addition the resulting X509Certificate implementation will contain the private key.
data - The byte stream representation to convert.passPhrase - If the byte stream is a PKCS12 representation, then the then the pass phrase is used to decrypt the stream. Can be
null if the stream is an encoded X509Certificate and not a PKCS12 byte stream.public X509Certificate certFromFile(String certFile)
certFile - The file to load into a certificate object.public static CertUtils.CertContainer toCertContainer(byte[] data) throws CertificateConversionException
data - The raw byte data that is stored in the Certificate data store.CertificateConversionExceptionpublic static CertUtils.CertContainer toCertContainer(byte[] data, boolean loadPrivateKey) throws CertificateConversionException
CertificateConversionExceptionprotected static boolean isByteDataWrappedKeyPair(byte[] data)
public static CertUtils.CertContainer toCertContainer(byte[] data, char[] keyStorePassPhrase, char[] privateKeyPassPhrase) throws CertificateConversionException
CertificateConversionExceptionpublic static CertUtils.CertContainer toCertContainer(byte[] data, char[] keyStorePassPhrase, char[] privateKeyPassPhrase, boolean loadPrivateKey) throws CertificateConversionException
data - A DER encoded representation of either an X509 certificate, an unencrypted PKCS12 container, or
a combination of an X509Certificate and wrapped private key.CertificateConversionExceptionpublic static byte[] certAndWrappedKeyToRawByteFormat(byte[] wrappedKey,
X509Certificate cert)
throws CertificateConversionException
CertificateConversionExceptionCopyright © 2025. All rights reserved.