public class SSLeayPrivateKey
extends java.lang.Object
implements java.security.PrivateKey
SSLeayPrivateKey
is used to read/write and decrypt/encrypt
private keys created with SSLeay or OpenSSL, respectively.
Constructor and Description |
---|
SSLeayPrivateKey(java.io.InputStream is)
Reads a private key created by SSLeay from the specified file.
|
SSLeayPrivateKey(java.security.PrivateKey privateKey)
This constructor gets a private key object to convert it into the OpenSSL format.
|
SSLeayPrivateKey(java.lang.String fileName)
Reads a private key created by SSLeay from the specified file.
|
Modifier and Type | Method and Description |
---|---|
void |
decrypt(java.lang.String password)
Decrypts this private key.
|
void |
encrypt(java.lang.String password,
java.lang.String encryptionAlg,
byte[] iv)
Encrypts this private key.
|
java.lang.String |
getAlgorithm()
Returns the symmetric encryption algorithm used to protect this private key.
|
byte[] |
getEncoded()
This method returns the DER encoded OpenSSL key which has PKCS#1
format.
|
java.lang.String |
getFormat()
Returns the format used to encode the key or null if the
key does not support encoding.
|
java.security.PrivateKey |
getPrivateKey()
Returns the included private key.
|
boolean |
isEncrypted()
Test if this private key is encrypted.
|
void |
writeTo(java.io.OutputStream out)
Write the SSLeayPrivateKey to a file.
|
public SSLeayPrivateKey(java.security.PrivateKey privateKey) throws java.security.InvalidKeyException, CodingException
privateKey
- the key objectjava.security.InvalidKeyException
- if the key is invalidCodingException
- if the key cannot be encodedpublic SSLeayPrivateKey(java.lang.String fileName) throws java.io.IOException, java.security.InvalidKeyException
fileName
- the name of the file containing the private keyjava.io.IOException
- if an error occurs during reading the keyjava.security.InvalidKeyException
- if the key can not be parsedpublic SSLeayPrivateKey(java.io.InputStream is) throws java.io.IOException, java.security.InvalidKeyException
is
- an input stream containing the private keyjava.io.IOException
- if an error occurs during reading the keyjava.security.InvalidKeyException
- if the key can not be parsedpublic boolean isEncrypted()
public java.security.PrivateKey getPrivateKey() throws java.security.InvalidKeyException
java.security.InvalidKeyException
- if an error occurs during parsing this private key or the
is not decrypted yetpublic void decrypt(java.lang.String password) throws java.security.InvalidKeyException
password
- the password to decrypt the private keyjava.security.InvalidKeyException
public void encrypt(java.lang.String password, java.lang.String encryptionAlg, byte[] iv) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.GeneralSecurityException
DES-CBC
, DES-EDE3-CBC
(default if null),
or IDEA/CBC/PKCS5Padding
. If iv is null, a new value is generatedpassword
- the password to decrypt the private keyencryptionAlg
- the algorithm used to encrypt the private keyiv
- the initialization vectorjava.security.InvalidKeyException
java.security.NoSuchAlgorithmException
java.security.GeneralSecurityException
public java.lang.String getAlgorithm()
getAlgorithm
in interface java.security.Key
public byte[] getEncoded()
getEncoded
in interface java.security.Key
public java.lang.String getFormat()
getFormat
in interface java.security.Key
public void writeTo(java.io.OutputStream out) throws java.io.IOException
java.io.IOException