Package org.compiere.util
Class SecureEngine
java.lang.Object
org.compiere.util.SecureEngine
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectDecrypt value (only implemented for String)static StringDecryption.
The methods must recognize clear text valuesstatic ObjectEncrypt value (only implemented for String).static StringEncryption.
The methods must recognize clear text valuesstatic StringGet Class Namestatic StringDeprecated.static StringgetPasswordHash(String algorithm, String value, byte[] salt) Hash the password with the given salt and algorithmstatic SecureRandomGet a SecureRandom instancestatic StringgetSHA256Digest(String value) Perform SHA-256 Digest of value.static StringgetSHA512Hash(int iterations, String value, byte[] salt) Convert String and salt to SHA-512 hash with iterations
https://www.owasp.org/index.php/Hashing_Javastatic voidInitialize/Test Securitystatic voidinit(Properties ctx) Initialize SecureEngine with ADEMPIERE_SECURE classstatic booleanisMatchHash(String hashedText, String hexSalt, String planText) Deprecated.static booleanisMatchHash(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.static booleanisSupportedPaswordHashAlgorithm(String hashAlgorithm) Check if the given password hash algorithm is supported
-
Field Details
-
DEFAULT_SECURE_RANDOM_ALGORITHM
- See Also:
-
-
Method Details
-
init
Initialize SecureEngine with ADEMPIERE_SECURE class- Parameters:
ctx- ignore
-
init
Initialize/Test Security- Parameters:
className- class name
-
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 iterationsvalue- messagesalt- salt- Returns:
- HexString of message (length = 128 characters)
- Throws:
UnsupportedEncodingExceptionNoSuchAlgorithmException
-
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:
NoSuchAlgorithmExceptionUnsupportedEncodingExceptionNoSuchProviderExceptionInvalidKeySpecException
-
isSupportedPaswordHashAlgorithm
Check if the given password hash algorithm is supported- Parameters:
hashAlgorithm-- Returns:
- true if supported, false otherwise
-
getDigest
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
Perform SHA-256 Digest of value.- Parameters:
value-- Returns:
- HexString of digested message (length = 64 characters)
-
encrypt
Encryption.
The methods must recognize clear text values- Parameters:
value- clear valueAD_Client_ID-- Returns:
- encrypted String
-
decrypt
Decryption.
The methods must recognize clear text values- Parameters:
value- encrypted valueAD_Client_ID-- Returns:
- decrypted String
-
encrypt
Encrypt value (only implemented for String).- Parameters:
value- clear valueAD_Client_ID-- Returns:
- encrypted String
-
decrypt
Decrypt value (only implemented for String)- Parameters:
value- encrypted value- Returns:
- decrypted String
-
isMatchHash
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
Get a SecureRandom instance- Returns:
- SecureRandom instance
- Throws:
NoSuchAlgorithmException
-