Class SecureEngine

java.lang.Object
org.compiere.util.SecureEngine

public class SecureEngine extends Object
Secure engine for encryption and decryption
Version:
$Id: SecureEngine.java,v 1.2 2006/07/30 00:52:23 jjanke Exp $
Author:
Jorg Janke
  • Field Details

  • Method Details

    • init

      public static void init(Properties ctx)
      Initialize SecureEngine with ADEMPIERE_SECURE class
      Parameters:
      ctx - ignore
    • init

      public static void init(String className)
      Initialize/Test Security
      Parameters:
      className - class name
    • getClassName

      public static String getClassName()
      Get Class Name
      Returns:
      class name
    • getSHA512Hash

      public static String getSHA512Hash(int iterations, String value, byte[] salt) throws NoSuchAlgorithmException, UnsupportedEncodingException
      Convert String and salt to SHA-512 hash with iterations
      https://www.owasp.org/index.php/Hashing_Java
      Parameters:
      iterations - number of iterations
      value - message
      salt - salt
      Returns:
      HexString of message (length = 128 characters)
      Throws:
      UnsupportedEncodingException
      NoSuchAlgorithmException
    • getPasswordHash

      public static String getPasswordHash(String algorithm, String value, byte[] salt) throws NoSuchAlgorithmException, UnsupportedEncodingException, NoSuchProviderException, InvalidKeySpecException
      Hash the password with the given salt and algorithm
      Parameters:
      algorithm -
      value -
      salt -
      Returns:
      HexString of hashed password
      Throws:
      NoSuchAlgorithmException
      UnsupportedEncodingException
      NoSuchProviderException
      InvalidKeySpecException
    • isSupportedPaswordHashAlgorithm

      public static boolean isSupportedPaswordHashAlgorithm(String hashAlgorithm)
      Check if the given password hash algorithm is supported
      Parameters:
      hashAlgorithm -
      Returns:
      true if supported, false otherwise
    • getDigest

      @Deprecated public static String getDigest(String value)
      Deprecated.
      Perform MD5 Digest of value.
      JavaScript version see - http://pajhome.org.uk/crypt/md5/index.html
      Parameters:
      value - message
      Returns:
      HexString of digested message (length = 32 characters)
    • getSHA256Digest

      public static String getSHA256Digest(String value)
      Perform SHA-256 Digest of value.
      Parameters:
      value -
      Returns:
      HexString of digested message (length = 64 characters)
    • encrypt

      public static String encrypt(String value, int AD_Client_ID)
      Encryption.
      The methods must recognize clear text values
      Parameters:
      value - clear value
      AD_Client_ID -
      Returns:
      encrypted String
    • decrypt

      public static String decrypt(String value, int AD_Client_ID)
      Decryption.
      The methods must recognize clear text values
      Parameters:
      value - encrypted value
      AD_Client_ID -
      Returns:
      decrypted String
    • encrypt

      public static Object encrypt(Object value, int AD_Client_ID)
      Encrypt value (only implemented for String).
      Parameters:
      value - clear value
      AD_Client_ID -
      Returns:
      encrypted String
    • decrypt

      public static Object decrypt(Object value, int AD_Client_ID)
      Decrypt value (only implemented for String)
      Parameters:
      value - encrypted value
      Returns:
      decrypted String
    • isMatchHash

      @Deprecated public static boolean isMatchHash(String hashedText, String hexSalt, String planText)
      Deprecated.
      Use salt in hex form and text hashed compare with plan text.
      If has exception in hash, log to server.
      Parameters:
      hashedText -
      hexSalt -
      planText -
      Returns:
      true if valid
    • isMatchHash

      public static boolean isMatchHash(String algorithm, String hashedText, String hexSalt, String plainText)
      Use salt in hex form and text hashed compare with plan text.
      If has exception in hash, log to server.
      Parameters:
      algorithm -
      hashedText -
      hexSalt -
      plainText -
      Returns:
      true if valid
    • getSecureRandom

      public static SecureRandom getSecureRandom() throws NoSuchAlgorithmException
      Get a SecureRandom instance
      Returns:
      SecureRandom instance
      Throws:
      NoSuchAlgorithmException