Class PasswordTextDecrypter

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 Details

    • PasswordTextDecrypter

      public PasswordTextDecrypter(char[] aPassword)
      Constructs a PasswordTextDecrypter 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

      public PasswordTextDecrypter(String aPassword)
      Constructs a PasswordTextDecrypter 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

      public String toDecrypted(String aInput) throws DecryptionException
      You pass in data of a given type and you get decrypted data of (another) given type.
      Specified by:
      toDecrypted in interface Decrypter<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 the CipherSpi.
      Specified by:
      toDecrypted in interface Decrypter<String,String,DecryptionException>
      Parameters:
      aBuffer - The input to be decrypted.
      aOffset - The offset to start decryption.
      aLength - The length to be decrypted
      aOutBuffer - 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 the Decrypter. 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