Package org.geysermc.floodgate.crypto
Interface FloodgateCipher
-
- All Known Implementing Classes:
AesCipher
public interface FloodgateCipherResponsible for both encrypting and decrypting data
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]HEADERstatic byte[]IDENTIFIERstatic intVERSION
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidcheckHeader(byte[] data)Checks if the header is valid.byte[]decrypt(byte[] data)Decrypts the given data using the Key provided ininit(Key)default byte[]decryptFromString(java.lang.String data)Decrypts a String.
This method internally callsdecrypt(byte[])by converting the UTF-8 String into a byte[]default @Nullable java.lang.StringdecryptToString(byte[] data)Decrypts a byte[] and turn it into a String.
This method internally callsdecrypt(byte[])and converts the returned byte[] into a String.byte[]encrypt(byte[] data)Encrypts the given data using the Key provided ininit(Key)default byte[]encryptFromString(java.lang.String data)Encrypts data from a String.
This method internally callsencrypt(byte[])voidinit(java.security.Key key)Initializes the instance by giving it the key it needs to encrypt or decrypt datastatic intversion(java.lang.String data)
-
-
-
Field Detail
-
VERSION
static final int VERSION
- See Also:
- Constant Field Values
-
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.ExceptionEncrypts the given data using the Key provided ininit(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.ExceptionEncrypts data from a String.
This method internally callsencrypt(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.ExceptionDecrypts the given data using the Key provided ininit(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.ExceptionDecrypts a byte[] and turn it into a String.
This method internally callsdecrypt(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.ExceptionDecrypts a String.
This method internally callsdecrypt(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 InvalidFormatExceptionChecks 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
-
-