java.lang.Object
org.refcodes.security.PasswordTextDecrypter
- All Implemented Interfaces:
org.refcodes.mixin.Disposable
,Decrypter<String,
String, DecryptionException>
public class PasswordTextDecrypter
extends Object
implements Decrypter<String,String,DecryptionException>
The
PasswordTextDecrypter
is a text Decrypter
for decrypting
String
instances with a given password using a "PBKDF2WithHmacSHA256"
key factory and a "AES/CBC/PKCS5Padding" cipher.
ATTENTION: THIS IMPLEMENTATION STORES AN OBFUSCATED PASSWORD AT RUNTIME!-
Constructor Summary
ConstructorsConstructorDescriptionPasswordTextDecrypter
(char[] aPassword) Constructs aPasswordTextDecrypter
instance with the given password.PasswordTextDecrypter
(String aPassword) Constructs aPasswordTextDecrypter
instance with the given password. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
int
toDecrypted
(byte[] aBuffer, int aOffset, int aLength, byte[] aOutBuffer, int aOutOffset) For compatibility with the java.security framework, ehttps://www.metacodes.proly to be integrated in a sub-class of theCipherSpi
.toDecrypted
(String aInput) You pass in data of a given type and you get decrypted data of (another) given type.
-
Constructor Details
-
PasswordTextDecrypter
public PasswordTextDecrypter(char[] aPassword) Constructs aPasswordTextDecrypter
instance with the given password. ATTENTION: THE PROVIDED CHAR ARRAY IS CLEARED (FILLED WITH ZEROS) AFTER BEING PASSED TO THIS CONSTRUCTOR!- Parameters:
aPassword
- The password to be used for decryption.
-
PasswordTextDecrypter
Constructs aPasswordTextDecrypter
instance with the given password. ATTENTION: USE A CHAR ARRAY INSTEAD OF A STRING AS PASSWORD IF YOU DON'T WANT YOUR PASSWORD TO HANG AROUND IN THE JVM'S STRING CACHE!- Parameters:
aPassword
- The password to be used for decryption.
-
-
Method Details
-
toDecrypted
You pass in data of a given type and you get decrypted data of (another) given type.- Specified by:
toDecrypted
in interfaceDecrypter<String,
String, DecryptionException> - Parameters:
aInput
- The input data to be decrypted.- Returns:
- The decrypted output data.
- Throws:
DecryptionException
-
toDecrypted
public int toDecrypted(byte[] aBuffer, int aOffset, int aLength, byte[] aOutBuffer, int aOutOffset) throws DecryptionException For compatibility with the java.security framework, ehttps://www.metacodes.proly to be integrated in a sub-class of theCipherSpi
.- Specified by:
toDecrypted
in interfaceDecrypter<String,
String, DecryptionException> - Parameters:
aBuffer
- The input to be decrypted.aOffset
- The offset to start decryption.aLength
- The length to be decryptedaOutBuffer
- The output where to decrypt to.aOutOffset
- The offset where to start writing the decrypted output.- Returns:
- The number of bytes decrypted.
- Throws:
DecryptionException
- Thrown in case a decryption issue occurred regarding theDecrypter
. Probably the configuration of yourEncrypter
does not fit the one of theDecrypter
.
-
dispose
public void dispose()- Specified by:
dispose
in interfaceorg.refcodes.mixin.Disposable
-