public class PrivKey extends Object
PrivateKey| Modifier and Type | Field and Description |
|---|---|
RSAPrivateKey |
privateKey |
| Constructor and Description |
|---|
PrivKey(byte[] encodedPrivateKey)
Constructor for PrivKey.
|
PrivKey(RSAPrivateKey privateKey)
Constructor for PrivKey.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getEncodedPrivateKey()
getEncodedPrivateKey.
|
RSAPrivateKey |
getPrivateKey()
Getter for the field
privateKey. |
static PrivKey |
load(byte[] keyBytes,
String password)
Load private key from key data.
|
static PrivKey |
load(File file)
Deprecated.
Use
load(File, String) or loadFromKeyStore(File, String) instead |
static PrivKey |
load(File file,
String password)
Load private key from a PEM encoded file using the given password.
|
static PrivKey |
load(InputStream is,
String password)
load.
|
static PrivKey |
loadFromKeyStore(File file,
String password)
Load private key from a key store (PKCS12) file
|
static PrivKey |
loadFromKeyStore(URL keystoreUrl,
String password)
Load private key from a PKCS12 key store
|
void |
save(File file)
Save the key in a binary file.
|
void |
save(File file,
String privateKeyPassword)
Save the private key to a PEM file.
|
void |
saveToKeyStore(Cert cert,
File file,
String privateKeyPassword,
String keyStorePassword,
String keyStoreType)
Save the identity to a password protected keystore.
|
public final RSAPrivateKey privateKey
public PrivKey(byte[] encodedPrivateKey)
throws IOException,
InvalidKeySpecException,
NoSuchAlgorithmException
Constructor for PrivKey.
encodedPrivateKey - an array of byte.IOException - if any.InvalidKeySpecException - if any.NoSuchAlgorithmException - if any.public PrivKey(RSAPrivateKey privateKey)
Constructor for PrivKey.
privateKey - a RSAPrivateKey object.public static PrivKey load(byte[] keyBytes, String password) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, InvalidParameterSpecException
@Deprecated public static PrivKey load(File file) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException
load(File, String) or loadFromKeyStore(File, String) insteadpublic static PrivKey load(File file, String password) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, InvalidParameterSpecException
public static PrivKey load(InputStream is, String password) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, InvalidParameterSpecException
load.
is - a InputStream object.password - a String object.PrivKey object.IOException - if any.NoSuchAlgorithmException - if any.InvalidKeySpecException - if any.NoSuchPaddingException - if any.InvalidKeyException - if any.InvalidAlgorithmParameterException - if any.IllegalBlockSizeException - if any.BadPaddingException - if any.InvalidParameterSpecException - if any.public static PrivKey loadFromKeyStore(File file, String password) throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, KeyStoreException
file - key store filepassword - password to key storeIOException - if any.KeyStoreException - if any.CertificateException - if any.NoSuchAlgorithmException - if any.UnrecoverableKeyException - if any.public static PrivKey loadFromKeyStore(URL keystoreUrl, String password) throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, KeyStoreException
keystoreUrl - url to key storepassword - password to key storeIOException - if any.KeyStoreException - if any.CertificateException - if any.NoSuchAlgorithmException - if any.UnrecoverableKeyException - if any.public byte[] getEncodedPrivateKey()
getEncodedPrivateKey.
public RSAPrivateKey getPrivateKey()
Getter for the field privateKey.
RSAPrivateKey object.public void save(File file) throws IOException
file - a File object.IOException - if any.public void save(File file, String privateKeyPassword) throws IOException
file - the fileprivateKeyPassword - the password used to store the keyIOException - if any.public void saveToKeyStore(Cert cert, File file, String privateKeyPassword, String keyStorePassword, String keyStoreType) throws IOException, KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException
cert - the certificate used to chain the keyfile - the file used to store the keyprivateKeyPassword - the password to secure the private key, must not be null for JKSkeyStorePassword - the password to the key store, must not be nullkeyStoreType - key store type, either "PKCS12" or "JKS"IOException - if the file cannot be written toNoSuchProviderException - Bouncy Castle Provider not foundKeyStoreException - keystore failedCertificateException - certificate problemNoSuchAlgorithmException - cryptographic algorithm not foundCopyright © 2026. All rights reserved.