public final class SymmetricAlgorithm extends Object implements EncryptionAlgorithm
Main implementation of encryption algorithms that use symmetric key based on existing javax.crypto package.
This base implementation generates a new random initialization vector for every message and includes it in
output. This allows to use one instance for different messages (otherwise it would be dangerous to use
same combination of key and IV for every message). This combining of IV with the encrypted message implies that this
implementation will be compatible primarily with itself (this library). If another tool (on the other end) will
be used, you must pass information what CombineAlgorithm is used to that tool or implement new one which
will be compatible with it. Inputs and outputs of String-based methods expect/provide strings in HEX format.
This base class also expects input to padded to the correct length, so it is not recommended to use NoPadding variants of algorithm.
Inputs and outputs from this encryption are bytes represented in HEX string.
This class is immutable and can be considered thread safe. It is not allowed to extend this class to ensure it stays that way.
AESBuilder,
TripleDESBuilder| Modifier | Constructor and Description |
|---|---|
protected |
SymmetricAlgorithm(String cipherName,
CryptoKeyFactory keyFactory,
CombineAlgorithm combineAlgorithm,
BytesRepresentation bytesRepresentation,
String encoding)
Creates a new instance of base symmetric algorithm.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decrypt(byte[] input)
Decrypts specified array of bytes.
|
String |
decrypt(String input)
Decrypts specified input text using default UTF-8 encoding.
|
byte[] |
encrypt(byte[] input)
Encrypts specified array of bytes.
|
String |
encrypt(String input)
Encrypts specified input text.
|
protected SymmetricAlgorithm(String cipherName, CryptoKeyFactory keyFactory, CombineAlgorithm combineAlgorithm, BytesRepresentation bytesRepresentation, String encoding) throws EncryptionException
cipherName - name of crypto algorithmkeyFactory - factory used for creation of encryption keycombineAlgorithm - algorithm for combining IV and cipher textbytesRepresentation - representation of byte arrays in Stringencoding - encoding used for stringsEncryptionException - possible exception when algorithm cannot be createdpublic byte[] encrypt(byte[] input)
throws EncryptionException
EncryptionAlgorithmencrypt in interface EncryptionAlgorithminput - input bytes to be encryptedEncryptionException - possible exception when encryption failspublic String encrypt(String input) throws EncryptionException
EncryptionAlgorithmencrypt in interface EncryptionAlgorithminput - input text to be encryptedEncryptionException - possible exception when encryption failspublic byte[] decrypt(byte[] input)
throws EncryptionException
EncryptionAlgorithmdecrypt in interface EncryptionAlgorithminput - input bytes to be decryptedEncryptionException - possible exception when decryption failspublic String decrypt(String input) throws EncryptionException
EncryptionAlgorithmdecrypt in interface EncryptionAlgorithminput - input text to be decryptedEncryptionException - possible exception when decryption failsCopyright © 2014. All rights reserved.