|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.vt.middleware.crypt.AbstractAlgorithm
edu.vt.middleware.crypt.AbstractEncryptionAlgorithm
public abstract class AbstractEncryptionAlgorithm
Base class for symmetric and asymmetric encryption algorithms. This class is
essentially a wrapper for the Cipher class.
| Field Summary | |
|---|---|
protected Cipher |
cipher
Encryption/decription cipher. |
protected int |
cipherMode
Either Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE. |
protected Key |
key
Key used for encryption or decryption. |
protected String |
mode
Mode used for encryption and decryption. |
protected String |
padding
Padding used for encryption and decryption. |
| Fields inherited from class edu.vt.middleware.crypt.AbstractAlgorithm |
|---|
algorithm, logger, randomByteSize, randomProvider |
| Constructor Summary | |
|---|---|
protected |
AbstractEncryptionAlgorithm(String cipherAlgorithm,
String cipherModeName,
String cipherPadding)
Creates a new encryption algorithm that uses a cipher of the given name. |
| Method Summary | |
|---|---|
protected byte[] |
crypt(byte[] in)
Based on current cipher mode, encrypts or decrypts the given input data. |
protected void |
crypt(InputStream in,
OutputStream out)
Based on current cipher mode, encrypts or decrypts the data in the given input stream into resulting data in the output stream. |
byte[] |
decrypt(byte[] ciphertext)
Decrypts the given ciphertext bytes into a byte array of plaintext using the decryption key. |
void |
decrypt(InputStream in,
OutputStream out)
Decrypts the data in the given ciphertext input stream into plaintext in the output stream. |
byte[] |
decrypt(String ciphertext,
Converter converter)
Decrypts a string representation of ciphertext bytes into a byte array of plaintext using the decryption key. |
byte[] |
encrypt(byte[] plaintext)
Encrypts the given plaintext bytes into a byte array of ciphertext using the encryption key. |
String |
encrypt(byte[] plaintext,
Converter converter)
Encrypts the given plaintext bytes into a ciphertext string using the conversion strategy provided by the given converter. |
void |
encrypt(InputStream in,
OutputStream out)
Encrypts the data in the given plaintext input stream into ciphertext in the output stream. |
protected abstract AlgorithmParameterSpec |
getAlgorithmParameterSpec()
Gets the algorithm parameter specification for this algorithm. |
int |
getBlockSize()
Gets the block size of the encryption algorithm cipher in bytes. |
protected abstract int |
getChunkSize()
Gets the chunk size for buffers using in stream-based encryption and decryption operations. |
int |
getCipherMode()
Gets the cipher mode indicating whether this instance is currently initialized for encryption or decryption. |
String |
getMode()
Gets the encryption mode. |
String |
getPadding()
Gets the encryption padding method. |
protected void |
init(int encryptOrDecrypt)
Initializes cipher for either encryption or decryption. |
protected void |
initCipher()
Initializes the underlying Cipher object using AbstractAlgorithm.algorithm,
mode, and padding. |
void |
initDecrypt()
Initializes this instance for decryption operations. |
void |
initEncrypt()
Initializes this instance for encryption operations. |
void |
setKey(Key k)
Sets the key used for encryption/decryption. |
String |
toString()
|
| Methods inherited from class edu.vt.middleware.crypt.AbstractAlgorithm |
|---|
getAlgorithm, getRandomData, setRandomProvider |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface edu.vt.middleware.crypt.Algorithm |
|---|
getAlgorithm, getRandomData, setRandomProvider |
| Field Detail |
|---|
protected Cipher cipher
protected String mode
protected String padding
protected int cipherMode
Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE.
protected Key key
| Constructor Detail |
|---|
protected AbstractEncryptionAlgorithm(String cipherAlgorithm,
String cipherModeName,
String cipherPadding)
cipherAlgorithm - Cipher algorithm name.cipherModeName - Cipher mode.cipherPadding - Cipher padding method.| Method Detail |
|---|
public String getMode()
getMode in interface EncryptionAlgorithmpublic String getPadding()
getPadding in interface EncryptionAlgorithmpublic void setKey(Key k)
setKey in interface EncryptionAlgorithmk - Public, private, or secret key used for encryption or
decryption.public int getCipherMode()
getCipherMode in interface EncryptionAlgorithmEncryptionAlgorithm.initEncrypt() or EncryptionAlgorithm.initDecrypt().public int getBlockSize()
getBlockSize in interface EncryptionAlgorithm
public void initEncrypt()
throws CryptException
initEncrypt in interface EncryptionAlgorithmCryptException - On cryptographic configuration errors.
public void initDecrypt()
throws CryptException
initDecrypt in interface EncryptionAlgorithmCryptException - On cryptographic configuration errors.
public byte[] encrypt(byte[] plaintext)
throws CryptException
encrypt in interface EncryptionAlgorithmplaintext - Input plaintext bytes.
CryptException - On encryption errors.
public String encrypt(byte[] plaintext,
Converter converter)
throws CryptException
encrypt in interface EncryptionAlgorithmplaintext - Input plaintext bytes.converter - Converter that converts ciphertext output bytes to a
string representation.
CryptException - On encryption errors.
public void encrypt(InputStream in,
OutputStream out)
throws CryptException,
IOException
Base64FilterOutputStream or HexFilterOutputStream to produce ciphertext in
the output stream in an encoded string repreprestation.
encrypt in interface EncryptionAlgorithmin - Input stream of plaintext.out - Output stream of ciphertext.
CryptException - On encryption errors.
IOException - On stream read/write errors.
public byte[] decrypt(byte[] ciphertext)
throws CryptException
decrypt in interface EncryptionAlgorithmciphertext - Input ciphertext bytes.
CryptException - On decryption errors.
public byte[] decrypt(String ciphertext,
Converter converter)
throws CryptException
decrypt in interface EncryptionAlgorithmciphertext - Input ciphertext bytes.converter - Converter that converts the ciphertext input string into
raw bytes required by the cipher algorithm.
CryptException - On decryption errors.
public void decrypt(InputStream in,
OutputStream out)
throws CryptException,
IOException
Base64FilterInputStream or HexFilterInputStream to consume ciphertext in
an encoded string representation.
decrypt in interface EncryptionAlgorithmin - Input stream of ciphertext.out - Output stream of plaintext.
CryptException - On decryption errors.
IOException - On stream read/write errors.public String toString()
toString in class AbstractAlgorithm
protected void initCipher()
throws CryptException
Cipher object using AbstractAlgorithm.algorithm,
mode, and padding.
CryptException - if the algorithm is not available from any
provider or if the provider is not available in the environment.
protected void init(int encryptOrDecrypt)
throws CryptException
cipher for either encryption or decryption.
encryptOrDecrypt - Either Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE.
CryptException - On cryptographic configuration errors.
protected byte[] crypt(byte[] in)
throws CryptException
in - Cipher input data.
CryptException - On encryption errors.
protected void crypt(InputStream in,
OutputStream out)
throws CryptException,
IOException
in - Input stream.out - Output stream.
CryptException - On encryption errors.
IOException - On stream read/write errors.protected abstract AlgorithmParameterSpec getAlgorithmParameterSpec()
protected abstract int getChunkSize()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||