Package no.polaric.core.util
Class SecUtils
java.lang.Object
no.polaric.core.util.SecUtils
Some utilities related to security.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final byte[]Compute a hash from the text.static final Stringb2hex(byte[] bytes) Hexadecimal representation of a byte array.static final byte[]static final Stringb64encode(byte[] x) static final byte[]static final Stringb91encode(byte[] x) static final byte[]Deprecated.MD5 is cryptographically broken and should not normally be used for security purposes.static final StringDeprecated.This method uses MD5 which is cryptographically broken.static final StringDeprecated.This method uses MD5 which is cryptographically broken.static StringEscape a text-string for use as a part of a regular expression.static final byte[]getRandom(int size) Generate a random key.static final byte[]Compute a HMAC SHA256 from data and a key.static final StringBase 64 encoded HMAC SHA256.static final Stringstatic final StringCompute a HMAC SHA256 from the text, represented as a hexadecimal string.static final byte[]Compute SHA-256 hash.static final StringxDigestB64(String txt, int n) Base 64 encoded digest (SHA256).static final StringxDigestB91(String txt, int n) static final StringxDigestHex(String txt) Compute a (SHA256) hash from the text, represented as a hexadecimal string.
-
Constructor Details
-
SecUtils
public SecUtils()
-
-
Method Details
-
getRandom
public static final byte[] getRandom(int size) Generate a random key. -
_digest
Compute a hash from the text. Text can be given as an array of bytes, a string or both. A string will be converted to bytes using the UTF-8 encoding before computing the hash. -
digest
Deprecated.MD5 is cryptographically broken and should not normally be used for security purposes. Use xDigest() for SHA-256 instead. This method is retained for compatibility with legacy systems that require MD5.Computes MD5 hash. -
xDigest
Compute SHA-256 hash. -
hmac
Compute a HMAC SHA256 from data and a key.- Returns:
- The hmac represented as a byte array.
-
digestHex
Deprecated.This method uses MD5 which is cryptographically broken. Use xDigestHex() instead.Compute a hash from the text, represented as a hexadecimal string. -
xDigestHex
Compute a (SHA256) hash from the text, represented as a hexadecimal string. -
hmacHex
Compute a HMAC SHA256 from the text, represented as a hexadecimal string. -
digestB64
Deprecated.This method uses MD5 which is cryptographically broken. Use xDigestB64() instead.Base 64 encoded digest. Returns n first characters of digest, encoded using the Base 64 method. -
xDigestB64
Base 64 encoded digest (SHA256). Returns n first characters of digest, encoded using the Base 64 method. -
xDigestB91
-
hmacB64
Base 64 encoded HMAC SHA256. Returns n first characters of digest, encoded using the Base 64 method. -
hmacB91
-
b64encode
-
b64decode
-
b91encode
-
b91decode
-
b2hex
Hexadecimal representation of a byte array. -
escape4regex
Escape a text-string for use as a part of a regular expression.
-