Class DataCodec<K>

java.lang.Object
org.geysermc.floodgate.core.crypto.DataCodec<K>
Direct Known Subclasses:
AesDataCodec, DataCodecKeyPair

public abstract class DataCodec<K> extends Object
Responsible for data integrity by either signing or encrypting the data.

Unlike KeyProducer, KeyCodec and Topping this class does have state. For every key a new instance should be made, or use init(Object) to reset that state.

  • Constructor Details

    • DataCodec

      public DataCodec()
  • Method Details

    • init

      public abstract void init(K key)
      Initializes the instance by giving it the key it needs to sign/verify or encrypt/decrypt data
      Parameters:
      key - the key used to sign/verify or encrypt/decrypt data
    • encode

      public abstract List<ByteBuffer> encode(ByteBuffer plainText) throws Exception
      Encodes the given data using the Key provided in init(Object)
      Parameters:
      plainText - the data to encode
      Returns:
      the encoded data
      Throws:
      Exception - when the encoding failed
    • decode

      public abstract ByteBuffer decode(List<ByteBuffer> dataSections) throws Exception
      Decodes the given data using the Key provided in init(Object)
      Parameters:
      dataSections - the data sections to decode
      Returns:
      the decoded data
      Throws:
      Exception - when the decoding failed
    • ensureAlgorithm

      protected void ensureAlgorithm(String algorithm, Key key)
    • ensureSectionCount

      protected void ensureSectionCount(int expectedSectionCount, String name, List<ByteBuffer> sections)