Class CryptUtils

java.lang.Object
ch.autumo.commons.utils.security.CryptUtils

public final class CryptUtils extends Object
Encryption Utilities.
  • Constructor Details

    • CryptUtils

      public CryptUtils()
  • Method Details

    • decodeIfNecessary

      public static String decodeIfNecessary(String data, SecureApplication app) throws UtilsException
      Decode data if encoded.
      Parameters:
      data - data
      app - 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 - data
      app - secure application
      internal - true for internal encodings
      Returns:
      decoded data
      Throws:
      UtilsException - if encoding fails
    • encode

      public static String encode(int mode, String data, SecureApplication app) throws UtilsException
      Standard encoding.
      Parameters:
      mode - encoding mode (algorithm)
      data - data
      app - 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 - data
      app - secure application
      internal - true for internal encodings
      Returns:
      encoded data
      Throws:
      UtilsException - if encosing fails
    • decode

      public static String decode(String data, SecureApplication app) throws UtilsException
      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 application
      internal - true for internal encodings
      Returns:
      encoded data
      Throws:
      UtilsException - if decoding fails
    • hashPw

      public static String hashPw(String password) throws UtilsException
      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

      public static boolean verifyPw(String password, String hashedPassword) throws UtilsException
      Verify password with configured HASH algorithm implementation.
      Parameters:
      password - password to check
      hashedPassword - hashed password previously loaded
      Returns:
      true if password match
      Throws:
      UtilsException - if password can't be verified
    • bytesToHex

      public static String bytesToHex(byte[] bytes)
      Bytes 2 HEX.
      Parameters:
      bytes - btes
      Returns:
      HEX string
    • hs2ba

      public static byte[] hs2ba(String s)
      String 2 byte array.
      Parameters:
      s - string
      Returns:
      byte array
    • ba2hs

      public static String ba2hs(byte[] b)
      Byte array 2 string.
      Parameters:
      b - byte array
      Returns:
      string