Enum Class MaapiCryptoType

Object
Enum<MaapiCryptoType>
com.tailf.maapi.MaapiCryptoType
All Implemented Interfaces:
Serializable, Comparable<MaapiCryptoType>, Constable

public enum MaapiCryptoType extends Enum<MaapiCryptoType>
Data encryption and decryption helper class for each supported encryption algorithm. Should be used through MaapiCrypto.
  • Enum Constant Details

  • Method Details

    • values

      public static MaapiCryptoType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static MaapiCryptoType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • fixedIV

      public boolean fixedIV(String value)
      Check if an encrypted string was encrypted using a random or a fixed IV.
      Parameters:
      value - The encrypted string.
      Returns:
      true if a fixed IV was used, false otherwise.
    • encrypt

      public String encrypt(byte[] key, String plaintext) throws MaapiException
      Encrypt a plaintext string using a supplied key.
      Parameters:
      key - The key to use when encrypting the plaintext.
      plaintext - The plaintext value to encrypt.
      Returns:
      The encrypted and base64 encoded value as a string with a prefix detailing the encryption algoritm used.
      Throws:
      MaapiException
    • decrypt

      public String decrypt(byte[] key, String encrypted) throws MaapiException
      Same as calling decrypt(byte[], String, byte[]) with the iv parameter set to null.
      Throws:
      MaapiException
    • decrypt

      public String decrypt(byte[] key, String encrypted, byte[] iv) throws MaapiException
      Decrypt an encrypted string using the given key and IV. The encrypted string is assumed to include the prefix of the encryption algorithm used. If the IV is included in the encrypted string the iv parameter should be set to null, otherwise ir should be the fixed IV user during encryption.
      Parameters:
      key - The key to use for decryption.
      encrypted - The string to decrypt.
      iv - The fixed IV to use for decryption or null if the IV is included in the encrypted string.
      Returns:
      The decrypted value as a string.
      Throws:
      MaapiException
    • find

      public static final MaapiCryptoType find(String encrypted)
      Find the crypto type corresponding for an encrypted string. Will check the prefix of the string to find the algorith used to encrypt it and return the MaapiCryptoType enum corresponding to that algorithm.
      Parameters:
      encrypted - The encrypted string to find the crypto type for.
      Returns:
      A MaapiCryptoType object or null if the type could not be found from the encrypted string.
    • isEncrypted

      public static final boolean isEncrypted(String value)
      Check if a string is encrypted or not based on the prefix of the string.
      Parameters:
      value - The string to check if it is encrypted.
      Returns:
      true of the value is encrypted, false otherwise.