public class KeyFileHelper extends Object
| Constructor and Description |
|---|
KeyFileHelper(MessageDigestAlgorithm passwordHashingAlgorithm)
Create a KeyFile helper that WILL hash passwords before they are used to PBKDF2 the
KeyRing. |
| Modifier and Type | Method and Description |
|---|---|
KeyRing |
decryptKeyRing(byte[] keyFileBytes,
String password)
This will decrypt the @link KeyRing} from the formatted KeyFile data using the password (if the helper was
created with a
MessageDigestAlgorithm the password will first be hashed using that algorithm, hex encoded
and changed to lowercase). |
KeyRing |
decryptKeyRingWithRescue(byte[] keyFileBytes,
String passphrase)
This will decrypt the @link KeyRing} from the formatted KeyFile data.
|
byte[] |
encrypt(KeyRing keyRing,
String password,
String passphrase)
This will PBKDF2 encrypt the
KeyRing using the password (if the helper was created with a MessageDigestAlgorithm the password will first be hashed using that algorithm, hex encoded and changed to
lowercase). |
byte[] |
encrypt(KeyRing keyRing,
String password,
String passphrase,
KeyFileSettings keyFileSettings)
This will PBKDF2 encrypt the
KeyRing using the password (if the helper was created with a MessageDigestAlgorithm the password will first be hashed using that algorithm, hex encoded and changed to
lowercase). |
byte[] |
encrypt(KeyRing keyRing,
String password,
String passphrase,
long version)
This will PBKDF2 encrypt the
KeyRing using the password (if the helper was created with a MessageDigestAlgorithm the password will first be hashed using that algorithm, hex encoded and changed to
lowercase). |
public KeyFileHelper(MessageDigestAlgorithm passwordHashingAlgorithm) throws NoSuchAlgorithmException
KeyRing. NOTE: if you
do not want to hash passwords, pass in null for the passwordHashingAlgorithm.passwordHashingAlgorithm - the algorithm to use when hashing the password (before encrypting)NoSuchAlgorithmException - thrown if the algorithm is not knownpublic KeyRing decryptKeyRing(byte[] keyFileBytes, String password) throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, IOException
MessageDigestAlgorithm the password will first be hashed using that algorithm, hex encoded
and changed to lowercase).keyFileBytes - the formatted KeyFile bytespassword - the password to use to decrypt the KeyRing - see description for hashing rulesKeyRing from the KeyFileNoSuchPaddingException - thrown if the padding is not supportedInvalidAlgorithmParameterException - thrown if the cipher algorithm is not supportedNoSuchAlgorithmException - thrown if the algorithm is not supportedIllegalBlockSizeException - thrown if the cipher block size is wrongBadPaddingException - thrown if the cipher padding is not supportedInvalidKeyException - thrown if there is an issue with the keyIOException - thrown if there was an error writing the formatted datapublic KeyRing decryptKeyRingWithRescue(byte[] keyFileBytes, String passphrase) throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, IOException
KeyRing.keyFileBytes - the formatted KeyFile bytespassphrase - the passphrase used to rescue the passwordKeyRing from the KeyFileNoSuchPaddingException - thrown if the padding is not supportedInvalidAlgorithmParameterException - thrown if the cipher algorithm is not supportedNoSuchAlgorithmException - thrown if the algorithm is not supportedIllegalBlockSizeException - thrown if the cipher block size is wrongBadPaddingException - thrown if the cipher padding is not supportedInvalidKeyException - thrown if there is an issue with the keyIOException - thrown if there was an error writing the formatted datapublic byte[] encrypt(KeyRing keyRing, String password, String passphrase) throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, IOException
KeyRing using the password (if the helper was created with a MessageDigestAlgorithm the password will first be hashed using that algorithm, hex encoded and changed to
lowercase). If a passphrase was included, password rescue will be included in the KeyFile format (this will
allow the usage of decryptKeyRingWithRescue(byte[], String) - get the KeyRing using
the passphrase). This will use KeyFileSettings.DEFAULT for the PBDKF2 parameters.keyRing - the KeyRing to encryptpassword - the password to use in the PBKDF2 encryption of the KeyRing - see description for
hashing rulespassphrase - the passphrase - used to encrypt the password for rescue - null if no rescue is desiredKeyRing and optional rescue)NoSuchPaddingException - thrown if the padding is not supportedInvalidKeyException - thrown if there is an issue with the keyNoSuchAlgorithmException - thrown if the algorithm is not supportedIllegalBlockSizeException - thrown if the cipher block size is wrongBadPaddingException - thrown if the cipher padding is not supportedInvalidAlgorithmParameterException - thrown if the cipher algorithm is not supportedIOException - thrown if there was an error writing the formatted datapublic byte[] encrypt(KeyRing keyRing, String password, String passphrase, long version) throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, IOException
KeyRing using the password (if the helper was created with a MessageDigestAlgorithm the password will first be hashed using that algorithm, hex encoded and changed to
lowercase). If a passphrase was included, password rescue will be included in the KeyFile format (this will
allow the usage of decryptKeyRingWithRescue(byte[], String) - get the KeyRing using
the passphrase). This will use KeyFileSettings.getSettings(long) to get the correct KeyFileSettings for the PBDKF2 parameters.keyRing - the KeyRing to encryptpassword - the password to use in the PBKDF2 encryption of the KeyRing - see description for
hashing rulespassphrase - the passphrase - used to encrypt the password for rescue - null if no rescue is desiredversion - the version of the KeyFileSettings to use for the PBKDF2 parametersKeyRing and optional rescue)NoSuchPaddingException - thrown if the padding is not supportedInvalidKeyException - thrown if there is an issue with the keyNoSuchAlgorithmException - thrown if the algorithm is not supportedIllegalBlockSizeException - thrown if the cipher block size is wrongBadPaddingException - thrown if the cipher padding is not supportedInvalidAlgorithmParameterException - thrown if the cipher algorithm is not supportedIOException - thrown if there was an error writing the formatted datapublic byte[] encrypt(KeyRing keyRing, String password, String passphrase, KeyFileSettings keyFileSettings) throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, IOException
KeyRing using the password (if the helper was created with a MessageDigestAlgorithm the password will first be hashed using that algorithm, hex encoded and changed to
lowercase). If a passphrase was included, password rescue will be included in the KeyFile format (this will
allow the usage of decryptKeyRingWithRescue(byte[], String) - get the KeyRing using
the passphrase). This will use the supplied KeyFileSettings for the PBDKF2 parameters.keyRing - the KeyRing to encryptpassword - the password to use in the PBKDF2 encryption of the KeyRing - see description for
hashing rulespassphrase - the passphrase - used to encrypt the password for rescue - null if no rescue is desiredkeyFileSettings - the PBKDF2 parametersKeyRing and optional rescue)NoSuchPaddingException - thrown if the padding is not supportedInvalidKeyException - thrown if there is an issue with the keyNoSuchAlgorithmException - thrown if the algorithm is not supportedIllegalBlockSizeException - thrown if the cipher block size is wrongBadPaddingException - thrown if the cipher padding is not supportedInvalidAlgorithmParameterException - thrown if the cipher algorithm is not supportedIOException - thrown if there was an error writing the formatted dataCopyright © 2021. All rights reserved.