public abstract class OpenSSLKey extends Object implements Serializable
Constructor and Description |
---|
OpenSSLKey(InputStream is)
Reads a OpenSSL private key from the specified input stream.
|
OpenSSLKey(PrivateKey key)
Converts a RSAPrivateCrtKey into OpenSSL key.
|
OpenSSLKey(String file)
Reads a OpenSSL private key from the specified file.
|
OpenSSLKey(String algorithm,
byte[] data)
Initializes the OpenSSL key from raw byte array.
|
Modifier and Type | Method and Description |
---|---|
void |
decrypt(byte[] password)
Decrypts the private key with given password.
|
void |
decrypt(String password)
Decrypts the private key with given password.
|
void |
encrypt(byte[] password)
Encrypts the private key with given password.
|
void |
encrypt(String password)
Encrypts the private key with given password.
|
boolean |
equals(Object other) |
protected byte[] |
getEncoded() |
protected abstract byte[] |
getEncoded(PrivateKey key) |
protected abstract PrivateKey |
getKey(String alg,
byte[] data) |
PrivateKey |
getPrivateKey()
Returns the JCE (RSAPrivateCrtKey) key.
|
protected String |
getProvider() |
int |
hashCode() |
boolean |
isEncrypted()
Check if the key was encrypted or not.
|
void |
setEncryptionAlgorithm(String alg)
Sets algorithm for encryption.
|
void |
writeTo(OutputStream output)
Writes the private key to the specified output stream in PEM
format.
|
void |
writeTo(String file)
Writes the private key to the specified file in PEM format.
|
void |
writeTo(Writer w)
Writes the private key to the specified writer in PEM format.
|
public OpenSSLKey(InputStream is) throws IOException, GeneralSecurityException
is
- input stream with OpenSSL key in PEM format.IOException
- if I/O problems.GeneralSecurityException
- if problems with the keypublic OpenSSLKey(String file) throws IOException, GeneralSecurityException
file
- file containing the OpenSSL key in PEM format.IOException
- if I/O problems.GeneralSecurityException
- if problems with the keypublic OpenSSLKey(PrivateKey key)
key
- private key - must be a RSAPrivateCrtKeypublic OpenSSLKey(String algorithm, byte[] data) throws GeneralSecurityException
algorithm
- the algorithm of the key. Currently only RSA algorithm is supported.data
- the DER encoded key data. If RSA algorithm, the key must be in PKCS#1 format.GeneralSecurityException
- if any security problems.protected byte[] getEncoded()
public boolean isEncrypted()
public void decrypt(String password) throws GeneralSecurityException
password
- password to decrypt the key with.GeneralSecurityException
- whenever an error occurs during decryption.public void decrypt(byte[] password) throws GeneralSecurityException
password
- password to decrypt the key with.GeneralSecurityException
- whenever an error occurs during decryption.public void encrypt(String password) throws GeneralSecurityException
password
- password to encrypt the key with.GeneralSecurityException
- whenever an error occurs during encryption.public void encrypt(byte[] password) throws GeneralSecurityException
password
- password to encrypt the key with.GeneralSecurityException
- whenever an error occurs during encryption.public void setEncryptionAlgorithm(String alg) throws GeneralSecurityException
alg
- algorithm for encryptionGeneralSecurityException
- if algorithm is not supportedpublic PrivateKey getPrivateKey()
public void writeTo(OutputStream output) throws IOException
output
- output stream to write the key to.IOException
- if I/O problems writing the keypublic void writeTo(Writer w) throws IOException
w
- writer to output the key to.IOException
- if I/O problems writing the keypublic void writeTo(String file) throws IOException
file
- file to write the key to.IOException
- if I/O problems writing the keyprotected abstract byte[] getEncoded(PrivateKey key)
protected abstract PrivateKey getKey(String alg, byte[] data) throws GeneralSecurityException
GeneralSecurityException
protected String getProvider()
Copyright © 2016. All rights reserved.