public final class PEMEncodable extends Object
| Modifier and Type | Method and Description |
|---|---|
static PEMEncodable |
create(Certificate certificate)
Creates a
PEMEncodable from a Certificate object |
static PEMEncodable |
create(Key key)
Creates a
PEMEncodable from a Key object |
static PEMEncodable |
create(KeyPair keyPair)
Creates a
PEMEncodable from a KeyPair object |
static PEMEncodable |
decode(String pem)
Creates a
PEMEncodable by decoding PEM formated data from a String |
static PEMEncodable |
decode(String pem,
char[] passphrase)
Creates a
PEMEncodable by decoding PEM formated data from a String |
String |
encode()
Encodes the current stored information in PEM format and returns it as a
String |
static byte[] |
getKeyDigest(Key k,
String algorithm)
Generates an digest from a Key object in the specified digest format.
|
static byte[] |
getKeyDigestMD5(Key k)
Generates an MD5 digest from a Key object
|
static byte[] |
getKeyDigestSHA1(Key k)
Generates an SHA1 digest from a Key object
|
String |
getPrivateKeyFingerprint()
Obtains the fingerprint of the private key in the "ab:cd:ef:...:12" format, which basically is an SHA1 digest
from the key, encoded in hex format.
|
String |
getPublicKeyFingerprint()
Obtains the fingerprint of the public key in the "ab:cd:ef:...:12" format, which basically is an MD5 digest from
the key, encoded in hex format.
|
Object |
getRawObject()
Obtains raw JCA or BouncyCastle
Object from the read PEM. |
static PEMEncodable |
read(File pemFile)
Creates a
PEMEncodable by reading a PEM file |
static PEMEncodable |
read(File pemFile,
char[] passphrase)
Creates a
PEMEncodable by reading a PEM file |
Certificate |
toCertificate()
Obtain
Certificate object from the read PEM. |
KeyPair |
toKeyPair()
Obtain
KeyPair object with the public and private key from the decoded PEM. |
PrivateKey |
toPrivateKey()
Obtain
PrivateKey object from the read PEM. |
PublicKey |
toPublicKey()
Obtain
PublicKey object from the read PEM. |
void |
write(File pemFile)
Writes the current stored information in PEM formated
File |
@Nonnull public static PEMEncodable create(@Nonnull Key key)
PEMEncodable from a Key objectkey - Key object with the keyPEMEncodable object@Nonnull public static PEMEncodable create(@Nonnull KeyPair keyPair)
PEMEncodable from a KeyPair objectkeyPair - KeyPair object with the key pairPEMEncodable object@Nonnull public static PEMEncodable create(@Nonnull Certificate certificate)
PEMEncodable from a Certificate objectcertificate - Certificate object with the certificatePEMEncodable object@Nonnull public static PEMEncodable decode(@Nonnull String pem) throws IOException, UnrecoverableKeyException
PEMEncodable by decoding PEM formated data from a Stringpem - String with the PEM dataPEMEncodable objectIOException - launched if a problem exists reading the PEM informationUnrecoverableKeyException - in case PEM is passphrase protected and none or wrong is provided@Nonnull public static PEMEncodable decode(@Nonnull String pem, @Nullable char[] passphrase) throws IOException, UnrecoverableKeyException
PEMEncodable by decoding PEM formated data from a Stringpem - String with the PEM datapassphrase - passphrase for the encrypted PEM data. null if PEM data is not passphrase protected. The caller
is responsible for zeroing out the char[] after use to ensure the password does not stay in memory, e.g. with
Arrays.fill(passphrase, (char)0)PEMEncodable objectIOException - launched if a problem exists reading the PEM informationUnrecoverableKeyException - in case PEM is passphrase protected and none or wrong is provided@Nonnull public String encode() throws IOException
StringIOException - launched if a problem exists generating the PEM information@Nonnull public static PEMEncodable read(@Nonnull File pemFile) throws IOException, UnrecoverableKeyException
PEMEncodable by reading a PEM filepemFile - File pointing to the PEM file to readIOException - launched if a problem exists reading the PEM information or the FileUnrecoverableKeyException - in case PEM is passphrase protected and none or wrong is provided@Nonnull public static PEMEncodable read(@Nonnull File pemFile, @Nullable char[] passphrase) throws IOException, UnrecoverableKeyException
PEMEncodable by reading a PEM filepemFile - File pointing to the PEM file to readpassphrase - passphrase for the encrypted PEM data. null if PEM data is not passphrase protected. The caller
is responsible for zeroing out the char[] after use to ensure the password does not stay in memory, e.g. with
Arrays.fill(passphrase, (char)0)IOException - launched if a problem exists reading the PEM information or the FileUnrecoverableKeyException - in case PEM is passphrase protected and none or wrong is providedpublic void write(@Nonnull File pemFile) throws IOException
FilepemFile - PEM File to readIOException - launched if a problem exists generating the PEM information or writing the File@CheckForNull public KeyPair toKeyPair()
KeyPair object with the public and private key from the decoded PEM. No conversion is performed,
the read PEM must contain private and public key in order to obtain a KeyPair object, null will be
returned in all the other cases.KeyPair object with public and private keys or null if the read PEM didn't contain private and
public keys.@CheckForNull public PublicKey toPublicKey()
PublicKey object from the read PEM. If the PEM data contained other object type like
KeyPair or Certificate, the public key will be extracted from them.PublicKey with the public key, null if a public key could not be obtained from the current data@CheckForNull public Certificate toCertificate()
Certificate object from the read PEM.Certificate with the certificate, null if a certificate could not be obtained from the current
data@CheckForNull public PrivateKey toPrivateKey()
PrivateKey object from the read PEM. If the PEM data contained other object type like
KeyPair, the private key will be extracted from them.PrivateKey with the private key, null if a private key could not be obtained from the current
data@CheckForNull public Object getRawObject()
Object from the read PEM. Depending on the PEM nature or the object
passed to the PEMEncodable(Object pemObject), the returned object can be one of the following (not
exhaustive list) and any classes that inherit from them:
ContentInfo
ECNamedCurveParameterSpec
PKCS10CertificationRequest
X509CertificateObject
X509V2AttributeCertificate
Object read from the PEM@CheckForNull public String getPrivateKeyFingerprint()
@CheckForNull public String getPublicKeyFingerprint()
@Nonnull public static byte[] getKeyDigestSHA1(@Nonnull Key k)
k - the key to generate the digest from@Nonnull public static byte[] getKeyDigestMD5(@Nonnull Key k)
k - the key to generate the digest from@Nonnull public static byte[] getKeyDigest(@Nonnull Key k, @Nonnull String algorithm) throws NoSuchAlgorithmException
k - key to generate the digest fromalgorithm - digest formatNoSuchAlgorithmException - when provided digest algorithm is not availableCopyright © 2016. All rights reserved.