Package ch.autumo.commons.utils.security
Class CryptUtils
java.lang.Object
ch.autumo.commons.utils.security.CryptUtils
Encryption Utilities.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
ba2hs
(byte[] b) Byte array 2 string.static String
bytesToHex
(byte[] bytes) Bytes 2 HEX.static String
decode
(String data, SecureApplication app) Standard decoding.static String
decode
(String data, SecureApplication app, boolean internal) Standard decoding.static String
decodeIfNecessary
(String data, SecureApplication app) Decode data if encoded.static String
decodeIfNecessary
(String data, SecureApplication app, boolean internal) Decode data if encoded.static String
encode
(int mode, String data, SecureApplication app) Standard encoding.static String
encode
(int mode, String data, SecureApplication app, boolean internal) Standard encoding.static String
Hash a password with configured HASH algorithm implementation.static byte[]
String 2 byte array.static boolean
Verify password with configured HASH algorithm implementation.
-
Constructor Details
-
CryptUtils
public CryptUtils()
-
-
Method Details
-
decodeIfNecessary
Decode data if encoded.- Parameters:
data
- dataapp
- secure application- Returns:
- decoded data
- Throws:
UtilsException
- if encoding fails
-
decodeIfNecessary
public static String decodeIfNecessary(String data, SecureApplication app, boolean internal) throws UtilsException Decode data if encoded.- Parameters:
data
- dataapp
- secure applicationinternal
- true for internal encodings- Returns:
- decoded data
- Throws:
UtilsException
- if encoding fails
-
encode
Standard encoding.- Parameters:
mode
- encoding mode (algorithm)data
- dataapp
- secure application- Returns:
- encoded data
- Throws:
UtilsException
- if encoding fails
-
encode
public static String encode(int mode, String data, SecureApplication app, boolean internal) throws UtilsException Standard encoding.- Parameters:
mode
- encoding mode (algorithm)data
- dataapp
- secure applicationinternal
- true for internal encodings- Returns:
- encoded data
- Throws:
UtilsException
- if encosing fails
-
decode
Standard decoding.- Parameters:
data
- data, which includes mode:'mode:encodedstring'.app
- secure application- Returns:
- encoded data
- Throws:
UtilsException
- if decoding fails
-
decode
public static String decode(String data, SecureApplication app, boolean internal) throws UtilsException Standard decoding.- Parameters:
data
- data, which includes mode:'mode:encodedstring'.app
- secure applicationinternal
- true for internal encodings- Returns:
- encoded data
- Throws:
UtilsException
- if decoding fails
-
hashPw
Hash a password with configured HASH algorithm implementation. Cannot be reversed.- Parameters:
password
- password to hash- Returns:
- hashed password
- Throws:
UtilsException
- if hashing fails
-
verifyPw
Verify password with configured HASH algorithm implementation.- Parameters:
password
- password to checkhashedPassword
- hashed password previously loaded- Returns:
- true if password match
- Throws:
UtilsException
- if password can't be verified
-
bytesToHex
Bytes 2 HEX.- Parameters:
bytes
- btes- Returns:
- HEX string
-
hs2ba
String 2 byte array.- Parameters:
s
- string- Returns:
- byte array
-
ba2hs
Byte array 2 string.- Parameters:
b
- byte array- Returns:
- string
-