public class PrivateKeyReader extends Object
PrivateKeyReader is a utility class for reading private keys in *.der or *.pem
format.| Modifier and Type | Field and Description |
|---|---|
static String |
BEGIN_PRIVATE_KEY_PREFIX
The Constant BEGIN_PRIVATE_KEY_PREFIX.
|
static String |
BEGIN_RSA_PRIVATE_KEY_PREFIX
The Constant BEGIN_RSA_PRIVATE_KEY_PREFIX.
|
static String |
END_PRIVATE_KEY_SUFFIX
The Constant END_PRIVATE_KEY_SUFFIX.
|
static String |
END_RSA_PRIVATE_KEY_SUFFIX
The Constant END_RSA_PRIVATE_KEY_SUFFIX.
|
static String |
RSA_PRIVATE_KEY
The Constant RSA_PRIVATE_KEY.
|
| Constructor and Description |
|---|
PrivateKeyReader() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isPemFormat(File file)
Checks if the given
File is in pem format. |
static boolean |
isPrivateKeyPasswordProtected(File file)
Checks if the given
File( in *.der format) is password protected |
static String |
readPemFileAsBase64(File file)
Read the private key from a pem file as base64 encoded
String value. |
static PrivateKey |
readPemPrivateKey(File file)
Reads the given
File( in *.pem format) with the default RSA algorithm and returns the
PrivateKey object. |
static PrivateKey |
readPemPrivateKey(File file,
String algorithm)
Reads the given
File( in *.pem format) with given algorithm and returns the
PrivateKey object. |
static PrivateKey |
readPemPrivateKey(String privateKeyAsString,
String algorithm)
Reads the given
String( in *.pem format) with given algorithm and returns the
PrivateKey object. |
static PrivateKey |
readPrivateKey(byte[] privateKeyBytes)
Reads the given byte array with the default RSA algorithm and returns the
PrivateKey
object. |
static PrivateKey |
readPrivateKey(byte[] privateKeyBytes,
String algorithm)
Reads the given byte array with the given algorithm and returns the
PrivateKey
object. |
static PrivateKey |
readPrivateKey(File file)
Reads the given
File( in *.der format) with the default RSA algorithm and returns the
PrivateKey object. |
static PrivateKey |
readPrivateKey(File file,
String algorithm)
Reads the given
File( in *.der format) with the given algorithm and returns the
PrivateKey object. |
static PrivateKey |
readPrivateKey(File root,
String directory,
String fileName)
Constructs from the given root, parent directory and file name the file and reads the private
key.
|
public static final String RSA_PRIVATE_KEY
public static final String BEGIN_PRIVATE_KEY_PREFIX
public static final String END_PRIVATE_KEY_SUFFIX
public static final String BEGIN_RSA_PRIVATE_KEY_PREFIX
public static final String END_RSA_PRIVATE_KEY_SUFFIX
public static boolean isPrivateKeyPasswordProtected(File file) throws IOException
File( in *.der format) is password protectedfile - the file( in *.der format) that contains the private keyFile( in *.der format) is password protected otherwise
falseIOException - Signals that an I/O exception has occurred.public static boolean isPemFormat(File file) throws IOException
File is in pem format.file - the fileFile is in pem format otherwise falseIOException - Signals that an I/O exception has occurred.public static PrivateKey readPrivateKey(File file) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
File( in *.der format) with the default RSA algorithm and returns the
PrivateKey object.file - the file( in *.der format) that contains the private keyPrivateKey objectIOException - Signals that an I/O exception has occurred.NoSuchAlgorithmException - is thrown if instantiation of the cypher object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchProviderException - is thrown if the specified provider is not registered in the security provider
list.public static PrivateKey readPrivateKey(File file, String algorithm) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
File( in *.der format) with the given algorithm and returns the
PrivateKey object.file - the file( in *.der format) that contains the private keyalgorithm - the algorithmPrivateKey objectIOException - Signals that an I/O exception has occurred.NoSuchAlgorithmException - is thrown if instantiation of the cypher object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchProviderException - is thrown if the specified provider is not registered in the security provider
list.public static PrivateKey readPrivateKey(byte[] privateKeyBytes) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
PrivateKey
object.privateKeyBytes - the byte array that contains the private key bytesPrivateKey objectNoSuchAlgorithmException - is thrown if instantiation of the cypher object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchProviderException - is thrown if the specified provider is not registered in the security provider
list.public static PrivateKey readPrivateKey(byte[] privateKeyBytes, String algorithm) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
PrivateKey
object.privateKeyBytes - the byte array that contains the private key bytesalgorithm - the algorithm for the KeyFactoryPrivateKey objectNoSuchAlgorithmException - is thrown if instantiation of the cypher object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchProviderException - is thrown if the specified provider is not registered in the security provider
list.public static PrivateKey readPemPrivateKey(File file) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
File( in *.pem format) with the default RSA algorithm and returns the
PrivateKey object.file - the file( in *.pem format) that contains the private keyPrivateKey objectIOException - Signals that an I/O exception has occurred.NoSuchAlgorithmException - is thrown if instantiation of the cypher object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchProviderException - is thrown if the specified provider is not registered in the security provider
list.public static PrivateKey readPemPrivateKey(File file, String algorithm) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
File( in *.pem format) with given algorithm and returns the
PrivateKey object.file - the file( in *.pem format) that contains the private keyalgorithm - the algorithmPrivateKey objectIOException - Signals that an I/O exception has occurred.NoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchProviderException - is thrown if the specified provider is not registered in the security provider
list.public static PrivateKey readPemPrivateKey(String privateKeyAsString, String algorithm) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
String( in *.pem format) with given algorithm and returns the
PrivateKey object.privateKeyAsString - the private key as string( in *.pem format)algorithm - the algorithmPrivateKey objectNoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchProviderException - is thrown if the specified provider is not registered in the security provider
list.public static String readPemFileAsBase64(File file) throws IOException
String value.file - the file( in *.pem format) that contains the private keyString value.IOException - Signals that an I/O exception has occurred.public static PrivateKey readPrivateKey(File root, String directory, String fileName) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException, IOException
root - the root directory of the parent directorydirectory - the parent directory of the private key filefileName - the file name of the file that contains the private keyNoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchProviderException - the no such provider exceptionIOException - Signals that an I/O exception has occurred.Copyright © 2015–2019 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.