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[] HEADER  
      static byte[] IDENTIFIER  
      static int VERSION  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      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[] decryptFromString​(java.lang.String data)
      Decrypts a String.
      This method internally calls decrypt(byte[]) by converting the UTF-8 String into a byte[]
      default @Nullable java.lang.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[] encryptFromString​(java.lang.String data)
      Encrypts data from a String.
      This method internally calls encrypt(byte[])
      void init​(java.security.Key key)
      Initializes the instance by giving it the key it needs to encrypt or decrypt data
      static int version​(java.lang.String data)  
    • Field Detail

      • IDENTIFIER

        static final byte[] IDENTIFIER
      • HEADER

        static final byte[] HEADER
    • Method Detail

      • version

        static int version​(java.lang.String data)
      • init

        void init​(java.security.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 java.lang.Exception
        Encrypts the given data using the Key provided in init(Key)
        Parameters:
        data - the data to encrypt
        Returns:
        the encrypted data
        Throws:
        java.lang.Exception - when the encryption failed
      • encryptFromString

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

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

        default @Nullable java.lang.String decryptToString​(byte[] data)
                                                    throws java.lang.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:
        java.lang.Exception - when the decrypting failed
      • decryptFromString

        default byte[] decryptFromString​(java.lang.String data)
                                  throws java.lang.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:
        java.lang.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