Class Blowfish

java.lang.Object
org.jivesoftware.util.Blowfish
All Implemented Interfaces:
Encryptor

public class Blowfish extends Object implements Encryptor
A class that provides easy Blowfish encryption.
Author:
Markus Hahn <markus_hahn@gmx.net>, Gaston Dombiak
  • Constructor Details

    • Blowfish

      public Blowfish()
      Creates a new Blowfish object using the default key
    • Blowfish

      public Blowfish(String password)
      Creates a new Blowfish object using the specified key (oversized password will be cut).
      Parameters:
      password - the password (treated as a real unicode array)
  • Method Details

    • encryptString

      public String encryptString(String sPlainText)
      Encrypts a string (treated in UNICODE).
      Parameters:
      sPlainText - string to encrypt
      Returns:
      encrypted string in binhex format
    • decryptString

      public String decryptString(String sCipherText)
      decrypts a hexbin string (handling is case-sensitive)
      Parameters:
      sCipherText - hexbin string to decrypt
      Returns:
      decrypted string (null equals an error)
    • destroy

      public void destroy()
      destroys (clears) the encryption engine, after that the instance is not valid anymore
    • encrypt

      public String encrypt(String value)
      Description copied from interface: Encryptor
      Encrypt a clear text String.
      Specified by:
      encrypt in interface Encryptor
      Parameters:
      value - The clear text attribute
      Returns:
      The encrypted attribute, or null
    • encrypt

      public String encrypt(String value, byte[] iv)
      Description copied from interface: Encryptor
      Encrypt a clear text String.
      Specified by:
      encrypt in interface Encryptor
      Parameters:
      value - The clear text attribute
      iv - The IV to use, or null for the default IV
      Returns:
      The encrypted attribute, or null
    • decrypt

      public String decrypt(String value)
      Description copied from interface: Encryptor
      Decrypt an encrypted String.
      Specified by:
      decrypt in interface Encryptor
      Parameters:
      value - The encrypted attribute in Base64 encoding
      Returns:
      The clear text attribute, or null
    • decrypt

      public String decrypt(String value, byte[] iv)
      Description copied from interface: Encryptor
      Decrypt an encrypted String.
      Specified by:
      decrypt in interface Encryptor
      Parameters:
      value - The encrypted attribute in Base64 encoding
      iv - The IV to use, or null for the default IV
      Returns:
      The clear text attribute, or null
    • setKey

      public void setKey(String key)
      Sets the password to be used for encryption/decryption using the KDF configured in security.xml.
      Specified by:
      setKey in interface Encryptor
      Parameters:
      key - The password to use for encryption
    • setKey

      public void setKey(String key, String kdf)
      Sets the password to be used for encryption/decryption with an explicit KDF. This overload is primarily used during migration from SHA1 to PBKDF2, where we need two Blowfish instances with different KDFs operating simultaneously (one to decrypt with SHA1, one to encrypt with PBKDF2).
      Parameters:
      key - The password to use for encryption
      kdf - The key derivation function to use ("sha1" or "pbkdf2")
      Since:
      5.1.0