public abstract class AbstractCryptor extends Object implements Serializable
| Modifier and Type | Field and Description |
|---|---|
protected Cipher |
cipher
The Cipher object.
|
| Constructor and Description |
|---|
AbstractCryptor(String privateKey)
Constructor with a private key.
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
newAlgorithm()
Factory method for creating a new algorithm that will be used with the cipher object.
|
protected AlgorithmParameterSpec |
newAlgorithmParameterSpec(byte[] salt,
int iterationCount)
Factory method for creating a new
AlgorithmParameterSpec from the given salt and
iteration count. |
protected Cipher |
newCipher(int operationMode,
SecretKey key,
AlgorithmParameterSpec paramSpec,
String alg)
Factory method for creating a new
Cipher from the given parameters. |
protected Cipher |
newCipher(String privateKey)
Factory method for creating a new
Cipher from the given private key. |
protected Cipher |
newCipher(String privateKey,
String algorithm,
byte[] salt,
int iterationCount,
int operationMode)
Factory method for creating a new
Cipher from the given parameters. |
protected int |
newIterationCount()
Factory method for creating a new iteration count that will be used with the cipher object.
|
protected KeySpec |
newKeySpec(String privateKey,
byte[] salt,
int iterationCount)
Factory method for creating a new
KeySpec from the given private key. |
protected abstract int |
newOperationMode()
Abstact callback method for get the operation mode. the operation mode can be one of the
following values: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE
|
protected byte[] |
newSalt()
Factory method for creating a new salt that will be used with the cipher object.
|
protected SecretKeyFactory |
newSecretKeyFactory(String algorithm)
Factory method for creating a new
SecretKeyFactory from the given algorithm. |
protected void |
onInitialize()
This method initialize the cipher object.
|
protected Cipher cipher
public AbstractCryptor(String privateKey) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidAlgorithmParameterException, UnsupportedEncodingException
privateKey - The private key.InvalidAlgorithmParameterException - is thrown if initialization of the cypher object fails.NoSuchPaddingException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeyException - is thrown if initialization of the cypher object fails.NoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.UnsupportedEncodingException - is thrown if the named charset is not supported.protected void onInitialize()
throws InvalidKeyException,
NoSuchAlgorithmException,
InvalidKeySpecException,
NoSuchPaddingException,
InvalidAlgorithmParameterException,
UnsupportedEncodingException
InvalidAlgorithmParameterException - is thrown if initialization of the cypher object fails.NoSuchPaddingException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeyException - is thrown if initialization of the cypher object fails.UnsupportedEncodingException - is thrown if the named charset is not supported.protected Cipher newCipher(String privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, UnsupportedEncodingException
Cipher from the given private key. This method is
invoked in the constructor from the derived classes and can be overridden so users can
provide their own version of a new Cipher from the given private key.privateKey - the private keyCipher from the given private key.NoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchPaddingException - is thrown if instantiation of the cypher object fails.InvalidKeyException - is thrown if initialization of the cypher object fails.InvalidAlgorithmParameterException - is thrown if initialization of the cypher object fails.UnsupportedEncodingException - is thrown if the named charset is not supported.protected String newAlgorithm()
protected byte[] newSalt()
protected int newIterationCount()
protected abstract int newOperationMode()
protected Cipher newCipher(String privateKey, String algorithm, byte[] salt, int iterationCount, int operationMode) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, UnsupportedEncodingException
Cipher from the given parameters. This method is
invoked in the constructor from the derived classes and can be overridden so users can
provide their own version of a new Cipher from the given parameters.privateKey - the private keyalgorithm - the algorithmsalt - the salt.iterationCount - the iteration countoperationMode - the operation mode for the new cipher objectNoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.InvalidKeySpecException - is thrown if generation of the SecretKey object fails.NoSuchPaddingException - is thrown if instantiation of the cypher object fails.InvalidKeyException - is thrown if initialization of the cypher object fails.InvalidAlgorithmParameterException - is thrown if initialization of the cypher object fails.UnsupportedEncodingException - is thrown if the named charset is not supported.protected Cipher newCipher(int operationMode, SecretKey key, AlgorithmParameterSpec paramSpec, String alg) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
Cipher from the given parameters. This method is
invoked in the constructor from the derived classes and can be overridden so users can
provide their own version of a new Cipher from the given parameters.operationMode - the operation modekey - the keyparamSpec - the param specalg - the algNoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.NoSuchPaddingException - is thrown if instantiation of the cypher object fails.InvalidKeyException - is thrown if initialization of the cypher object fails.InvalidAlgorithmParameterException - is thrown if initialization of the cypher object fails.protected AlgorithmParameterSpec newAlgorithmParameterSpec(byte[] salt, int iterationCount)
AlgorithmParameterSpec from the given salt and
iteration count. This method is invoked in the constructor from the derived classes and can
be overridden so users can provide their own version of a new AlgorithmParameterSpec
from the given salt and iteration count.salt - the saltiterationCount - the iteration countAlgorithmParameterSpec from the given salt and iteration count.protected KeySpec newKeySpec(String privateKey, byte[] salt, int iterationCount)
KeySpec from the given private key. This method is
invoked in the constructor from the derived classes and can be overridden so users can
provide their own version of a new KeySpec from the given private key.privateKey - the private keysalt - the saltiterationCount - the iteration countKeySpec from the given private key.protected SecretKeyFactory newSecretKeyFactory(String algorithm) throws NoSuchAlgorithmException
SecretKeyFactory from the given algorithm. This
method is invoked in the constructor from the derived classes and can be overridden so users
can provide their own version of a new SecretKeyFactory from the given algorithm.algorithm - the algorithmSecretKeyFactory from the given algorithm.NoSuchAlgorithmException - is thrown if instantiation of the SecretKeyFactory object fails.Copyright © 2015–2016 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.