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 Details

    • PasswordTextEncrypter

      public PasswordTextEncrypter(char[] aPassword)
      Constructs a PasswordTextEncrypter 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 encryption.
    • PasswordTextEncrypter

      public PasswordTextEncrypter(String aPassword)
      Constructs a PasswordTextEncrypter 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 encryption.
  • Method Details

    • toEncrypted

      public String toEncrypted(String aInput) throws EncryptionException
      You pass in data of a given type and you get encrypted data of (another) given type.
      Specified by:
      toEncrypted in interface Encrypter<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 the CipherSpi.
      Specified by:
      toEncrypted in interface Encrypter<String,String,EncryptionException>
      Parameters:
      aBuffer - The input to be encrypted.
      aOffset - The offset to start encryption.
      aLength - The length to be encrypted
      aOutBuffer - 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 the Encrypter. Probably the configuration of your Encrypter does not fit the one of the Decrypter.
    • dispose

      public void dispose()
      Specified by:
      dispose in interface org.refcodes.mixin.Disposable