Package septogeddon.pluginquery.utils
Class EncryptionToolkit
java.lang.Object
septogeddon.pluginquery.utils.EncryptionToolkit
Encryption toolkit that holds both encryptor and decryptor Cipher
- Author:
- Thito Yalasatria Sunarya
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
encode()
Encode the EncryptionToolkit into byte array.static Key
Generate random AES key with 256 key sizeDecryption Cipher used to Decrypt byte arrayEncryption Cipher used to Encrypt byte arraygetKey()
The key instancestatic Key
Read key from a File.void
Save this EncryptionToolkit to a file to load it later.
-
Constructor Details
-
EncryptionToolkit
public EncryptionToolkit(Key key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException
-
-
Method Details
-
generateKey
Generate random AES key with 256 key size- Returns:
- Throws:
NoSuchAlgorithmException
-
readKey
Read key from a File. Only file that are encoded usingwriteKey(File)
orencode()
can be read cause it contains encoded algorithm name.- Parameters:
file
-- Returns:
- Throws:
IOException
-
getKey
The key instance- Returns:
-
encode
public byte[] encode()Encode the EncryptionToolkit into byte array. The first byte is the length of algorithm name used for the encryption. The next bytes is the algorithm name itself and the encoded key.- Returns:
-
getEncryptor
Encryption Cipher used to Encrypt byte array- Returns:
-
getDecryptor
Decryption Cipher used to Decrypt byte array- Returns:
-
writeKey
Save this EncryptionToolkit to a file to load it later.- Parameters:
file
-- Throws:
IOException
-