Interface FloodgateCipher

All Known Implementing Classes:
AesCipher

public interface FloodgateCipher
Responsible for both encrypting and decrypting data
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static byte[]
     
    static byte[]
     
    static int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    checkHeader​(byte[] data)
    Checks if the header is valid.
    byte[]
    decrypt​(byte[] data)
    Decrypts the given data using the Key provided in init(Key)
    default byte[]
    Decrypts a String.
    This method internally calls decrypt(byte[]) by converting the UTF-8 String into a byte[]
    default String
    decryptToString​(byte[] data)
    Decrypts a byte[] and turn it into a String.
    This method internally calls decrypt(byte[]) and converts the returned byte[] into a String.
    byte[]
    encrypt​(byte[] data)
    Encrypts the given data using the Key provided in init(Key)
    default byte[]
    Encrypts data from a String.
    This method internally calls encrypt(byte[])
    void
    init​(Key key)
    Initializes the instance by giving it the key it needs to encrypt or decrypt data
    static int
    version​(String data)
     
  • Field Details

    • VERSION

      static final int VERSION
      See Also:
      Constant Field Values
    • IDENTIFIER

      static final byte[] IDENTIFIER
  • Method Details

    • version

      static int version(String data)
    • init

      void init(Key key)
      Initializes the instance by giving it the key it needs to encrypt or decrypt data
      Parameters:
      key - the key used to encrypt and decrypt data
    • encrypt

      byte[] encrypt(byte[] data) throws Exception
      Encrypts the given data using the Key provided in init(Key)
      Parameters:
      data - the data to encrypt
      Returns:
      the encrypted data
      Throws:
      Exception - when the encryption failed
    • encryptFromString

      default byte[] encryptFromString(String data) throws Exception
      Encrypts data from a String.
      This method internally calls encrypt(byte[])
      Parameters:
      data - the data to encrypt
      Returns:
      the encrypted data
      Throws:
      Exception - when the encryption failed
    • decrypt

      byte[] decrypt(byte[] data) throws Exception
      Decrypts the given data using the Key provided in init(Key)
      Parameters:
      data - the data to decrypt
      Returns:
      the decrypted data
      Throws:
      Exception - when the decrypting failed
    • decryptToString

      default String decryptToString(byte[] data) throws Exception
      Decrypts a byte[] and turn it into a String.
      This method internally calls decrypt(byte[]) and converts the returned byte[] into a String.
      Parameters:
      data - the data to encrypt
      Returns:
      the decrypted data in a UTF-8 String
      Throws:
      Exception - when the decrypting failed
    • decryptFromString

      default byte[] decryptFromString(String data) throws Exception
      Decrypts a String.
      This method internally calls decrypt(byte[]) by converting the UTF-8 String into a byte[]
      Parameters:
      data - the data to decrypt
      Returns:
      the decrypted data in a byte[]
      Throws:
      Exception - when the decrypting failed
    • checkHeader

      default void checkHeader(byte[] data) throws InvalidFormatException
      Checks if the header is valid. This method will throw an InvalidFormatException when the header is invalid.
      Parameters:
      data - the data to check
      Throws:
      InvalidFormatException - when the header is invalid