Class SecretKeyEncryptor
java.lang.Object
org.deltava.crypt.SecretKeyEncryptor
- Direct Known Subclasses:
AESEncryptor
A class to support encrypting/decrypting data using a symetric secret key.
- Since:
- 1.0
- Version:
- 10.1
- Author:
- Luke
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SecretKeyEncryptor
(String algorithm) Create a new encryptor using a given algorithm. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
decrypt
(byte[] data) Decrypt a given amount of data.byte[]
encrypt
(byte[] data) Encrypt a given amount of data.final String
Returns the algorithm in use.protected void
Initialize the encryptor using a given key specification.protected void
Initialize the encryptor using a given secret key.protected static byte[]
trimKeySize
(byte[] rawKey, int maxSize) Helper method to trim a key if it is longer than a particular size.
-
Constructor Details
-
SecretKeyEncryptor
Create a new encryptor using a given algorithm.- Parameters:
algorithm
- the encryption algorithm to use.
-
-
Method Details
-
initKey
Initialize the encryptor using a given key specification.- Parameters:
spec
- the secret Key information- Throws:
CryptoException
- if the Secret Key cannot be initialized by the JVM
-
setKey
Initialize the encryptor using a given secret key.- Parameters:
key
- the secret Keyiv
- an optional initialization vector- Throws:
CryptoException
- if the cipher cannot be initialized by the JVM
-
getAlgorithm
-
encrypt
Encrypt a given amount of data.- Parameters:
data
- the data to encrypt- Returns:
- the encrypted data
- Throws:
CryptoException
- if something bad happens
-
decrypt
Decrypt a given amount of data.- Parameters:
data
- the data to decrypt- Returns:
- the clear-text data
- Throws:
CryptoException
- if something bad happens
-
trimKeySize
protected static byte[] trimKeySize(byte[] rawKey, int maxSize) Helper method to trim a key if it is longer than a particular size.- Parameters:
rawKey
- the raw key datamaxSize
- the maximum size in bytes- Returns:
- the trimmed key
-