Package org.kissweb

Class Crypto

java.lang.Object
org.kissweb.Crypto

public final class Crypto extends Object
This class provides the ability to encrypt/decrypt strings and byte arrays with very strong (AES) encryption. Author: Blake McBride
Date: 2/1/22

This class provides the ability to encrypt/decrypt strings and byte arrays with very strong (AES) encryption.
  • Constructor Details

    • Crypto

      public Crypto()
  • Method Details

    • encrypt

      public static String encrypt(String salt, String password, String valueToEnc) throws Exception
      Encrypt a string utilizing the passed in salt and password.

      While salt and password can be any size, they are added together and only the first 32 bytes are used.
      Parameters:
      salt - the salt or null
      password -
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encrypt

      public static String encrypt(String salt, String valueToEnc) throws Exception
      Encrypt a string utilizing the passed in salt and the default password.
      Parameters:
      salt - the salt or null
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encrypt

      public static String encrypt(String valueToEnc) throws Exception
      Encrypt using the default password and no salt.
      Parameters:
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encryptWithRandomSalt

      public static String encryptWithRandomSalt(String password, String valueToEnc) throws Exception
      Encrypt with a given password and random salt.
      Parameters:
      password -
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encryptWithRandomSalt

      public static String encryptWithRandomSalt(String valueToEnc) throws Exception
      Encrypt using the default password and random salt.
      Parameters:
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encrypt

      public static byte[] encrypt(String salt, String password, byte[] valueToEnc) throws Exception
      Encrypt a byte array utilizing the passed in salt and password.

      While salt and password can be any size, they are added together and only the first 32 bytes are used.
      Parameters:
      salt - the salt or null
      password -
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encrypt

      public static byte[] encrypt(String salt, byte[] valueToEnc) throws Exception
      Encrypt a byte array utilizing a salt and the default password.
      Parameters:
      salt - the salt or null
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encrypt

      public static byte[] encrypt(byte[] valueToEnc) throws Exception
      Encrypt with the default password and no salt.
      Parameters:
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encryptWithRandomSalt

      public static byte[] encryptWithRandomSalt(String password, byte[] valueToEnc) throws Exception
      Encrypt with the given password and random salt.
      Parameters:
      password -
      valueToEnc -
      Returns:
      Throws:
      Exception
    • encryptWithRandomSalt

      public static byte[] encryptWithRandomSalt(byte[] valueToEnc) throws Exception
      Encrypt with the default password and random salt.
      Parameters:
      valueToEnc -
      Returns:
      Throws:
      Exception
    • decrypt

      public static String decrypt(String salt, String password, String encryptedValue) throws Exception
      Decrypt a string utilizing the passed in salt and password.

      While salt and password can be any size, they are added together and only the first 32 bytes are used.
      Parameters:
      salt - the salt or null
      password -
      encryptedValue -
      Returns:
      Throws:
      Exception
    • decrypt

      public static String decrypt(String salt, String encryptedValue) throws Exception
      Decrypt a string utilizing the passed in salt and the default password.
      Parameters:
      salt - the salt or null
      encryptedValue -
      Returns:
      Throws:
      Exception
    • decryptWithRandomSalt

      public static String decryptWithRandomSalt(String password, String encryptedValue) throws Exception
      Decrypt a string that was encrypted with random salt using the provided password.
      Parameters:
      password -
      encryptedValue -
      Returns:
      Throws:
      Exception
    • decryptWithRandomSalt

      public static String decryptWithRandomSalt(String encryptedValue) throws Exception
      Decrypt a string that was encrypted with random salt using the default password.
      Parameters:
      encryptedValue -
      Returns:
      Throws:
      Exception
    • decrypt

      public static byte[] decrypt(String salt, String password, byte[] encryptedValue) throws Exception
      Decrypt a byte array utilizing the passed in salt and password.

      While salt and password can be any size, they are added together and only the first 32 bytes are used.
      Parameters:
      salt - the salt or null
      password -
      encryptedValue -
      Returns:
      Throws:
      Exception
    • decrypt

      public static byte[] decrypt(String salt, byte[] encryptedValue) throws Exception
      Decrypt a byte array utilizing a slat and the default password.
      Parameters:
      salt - the salt or null
      encryptedValue -
      Returns:
      Throws:
      Exception
    • decryptWithRandomSalt

      public static byte[] decryptWithRandomSalt(String password, byte[] encryptedValue) throws Exception
      Throws:
      Exception
    • decryptWithRandomSalt

      public static byte[] decryptWithRandomSalt(byte[] encryptedValue) throws Exception
      Throws:
      Exception
    • setDefaultPassword

      public static void setDefaultPassword(String password)
      Set the default password. This remains until it is changed.

      The password can be any size greater than 0 but only a max of the first 32 bytes will be used.
      Parameters:
      password - the password
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception