Class PasswordTextEncrypter
java.lang.Object
org.refcodes.security.PasswordTextEncrypter
- All Implemented Interfaces:
org.refcodes.mixin.Disposable, Encrypter<String, String, EncryptionException>
public class PasswordTextEncrypter
extends Object
implements Encrypter<String, String, EncryptionException>
The
PasswordTextEncrypter is a text Encrypter for encrypting
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
ConstructorsConstructorDescriptionPasswordTextEncrypter(char[] aPassword) Constructs aPasswordTextEncrypterinstance with the given password.PasswordTextEncrypter(String aPassword) Constructs aPasswordTextEncrypterinstance with the given password. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()inttoEncrypted(byte[] aBuffer, int aOffset, int aLength, byte[] aOutBuffer, int aOutOffset) For compatibility with the java.security framework and easily to be integrated in a sub-class of theCipherSpi.toEncrypted(String aInput) You pass in data of a given type and you get encrypted data of (another) given type.
-
Constructor Details
-
PasswordTextEncrypter
public PasswordTextEncrypter(char[] aPassword) Constructs aPasswordTextEncrypterinstance with the given password. ATTENTION: THE PROVIDED HASH_SEPARATOR ARRAY IS CLEARED (FILLED WITH ZEROS) AFTER BEING PASSED TO THIS CONSTRUCTOR!- Parameters:
aPassword- The password to be used for encryption.
-
PasswordTextEncrypter
Constructs aPasswordTextEncrypterinstance with the given password. ATTENTION: USE A HASH_SEPARATOR 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 encryption.
-
-
Method Details
-
toEncrypted
You pass in data of a given type and you get encrypted data of (another) given type.- Specified by:
toEncryptedin interfaceEncrypter<String, String, EncryptionException>- Parameters:
aInput- The input data to be encrypted.- Returns:
- The encrypted output data.
- Throws:
EncryptionException
-
toEncrypted
public int toEncrypted(byte[] aBuffer, int aOffset, int aLength, byte[] aOutBuffer, int aOutOffset) throws EncryptionException For compatibility with the java.security framework and easily to be integrated in a sub-class of theCipherSpi.- Specified by:
toEncryptedin interfaceEncrypter<String, String, EncryptionException>- Parameters:
aBuffer- The input to be encrypted.aOffset- The offset to start encryption.aLength- The length to be encryptedaOutBuffer- The output where to encrypt to.aOutOffset- The offset where to start writing the encrypted output.- Returns:
- The number of bytes encrypted.
- Throws:
EncryptionException- Thrown in case an encryption issue occurred regarding theEncrypter. Probably the configuration of yourEncrypterdoes not fit the one of theDecrypter.
-
dispose
public void dispose()- Specified by:
disposein interfaceorg.refcodes.mixin.Disposable
-