Class SecUtils

java.lang.Object
no.polaric.core.util.SecUtils

public class SecUtils extends Object
Some utilities related to security.
  • Constructor Details

    • SecUtils

      public SecUtils()
  • Method Details

    • getRandom

      public static final byte[] getRandom(int size)
      Generate a random key.
    • _digest

      public static final byte[] _digest(byte[] bytes, String txt, String algo)
      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 public static final byte[] digest(byte[] bytes, String txt)
      Deprecated.
      MD5 is cryptographically broken and should not be used for security purposes. Use xDigest() for SHA-256 instead. This method is retained only for compatibility with legacy systems that require MD5.
      Computes MD5 hash.
    • xDigest

      public static final byte[] xDigest(byte[] bytes, String txt)
    • hmac

      public static final byte[] hmac(String data, String key)
    • digestHex

      @Deprecated public static final String digestHex(String txt)
      Deprecated.
      This method uses MD5 which is cryptographically broken. Use xDigestHex() instead.
      Compute a hash from the text, represented as a hexadecimal string.
    • xDigestHex

      public static final String xDigestHex(String txt)
    • hmacHex

      public static final String hmacHex(String txt, String key)
    • digestB64

      @Deprecated public static final String digestB64(String txt, int n)
      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

      public static final String xDigestB64(String txt, int n)
    • hmacB64

      public static final String hmacB64(String txt, String key, int n)
    • b64encode

      public static final String b64encode(byte[] x)
    • b64decode

      public static final byte[] b64decode(String txt)
    • b2hex

      public static final String b2hex(byte[] bytes)
      Hexadecimal representation of a byte array.
    • escape4regex

      public static String escape4regex(String x)