|
||||||||||
| 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
edu.vt.middleware.crypt.symmetric.SymmetricAlgorithm
public class SymmetricAlgorithm
Provides symmetric encryption and decryption operations using a secret key.
| Field Summary | |
|---|---|
static String |
DEFAULT_MODE
Default mode used for encryption and decryption. |
static String |
DEFAULT_PADDING
Default padding used for encryption and decryption. |
protected byte[] |
iv
Initialization vector used for encryption. |
protected AlgorithmParameterSpec |
paramSpec
Cipher-specific initialization parameters provided to factory methods. |
| Fields inherited from class edu.vt.middleware.crypt.AbstractEncryptionAlgorithm |
|---|
cipher, cipherMode, key, mode, padding |
| Fields inherited from class edu.vt.middleware.crypt.AbstractAlgorithm |
|---|
algorithm, logger, randomByteSize, randomProvider |
| Constructor Summary | |
|---|---|
protected |
SymmetricAlgorithm(String cipherAlgorithm,
String cipherModeName,
String cipherPadding)
Creates a new instance that uses a cipher of the given algorithm. |
| Method Summary | |
|---|---|
SecretKey |
generateKey()
Generates a secret key of the default key size for encryption and decryption operations with this instance and others that use the same algorithm. |
SecretKey |
generateKey(int bitLength)
Generates a secret key of the given size for encryption and decryption operations with this instance and others that use the same algorithm. |
static SecretKey |
generateKey(String algorithm,
int bitLength,
SecureRandom random)
Generates a new secret key for encryption/decryption operations on a cipher of the given algorithm name. |
protected AlgorithmParameterSpec |
getAlgorithmParameterSpec()
Gets the algorithm parameter specification for this algorithm. |
int[] |
getAllowedKeyLengths()
Gets an array of key lengths that are acceptable for the cipher algorithm. |
protected int |
getChunkSize()
Gets the chunk size for buffers using in stream-based encryption and decryption operations. |
int |
getDefaultKeyLength()
Gets the default key length for this algorithm. |
int |
getMaxKeyLength()
Gets the maximum key length for this algorithm. |
int |
getMinKeyLength()
Gets the minimum key length for this algorithm. |
byte[] |
getRandomIV()
Gets a random initialization vector whose size is equal to the underlying cipher's block size. |
boolean |
hasIV()
Determines whether the cipher has been provided with iv data. |
boolean |
isValidKeyLength(int bitLength)
Determines whether the given key size in bits is valid for this symmetric cipher algorithm. |
static SymmetricAlgorithm |
newInstance(AlgorithmSpec spec)
Creates a new instance from an algorithm specification. |
static SymmetricAlgorithm |
newInstance(AlgorithmSpec spec,
AlgorithmParameterSpec cipherSpec)
Creates a new instance from an algorithm specification and cipher initialization parameters. |
static SymmetricAlgorithm |
newInstance(String cipherAlgorithm)
Creates a new instance that uses a cipher of the given algorithm and the default mode and padding. |
static SymmetricAlgorithm |
newInstance(String cipherAlgorithm,
String cipherModeName,
String cipherPadding)
Creates a new instance that uses a cipher of the given algorithm. |
void |
setIV(byte[] ivBytes)
Sets the encryption initialization vector. |
| Methods inherited from class edu.vt.middleware.crypt.AbstractEncryptionAlgorithm |
|---|
crypt, crypt, decrypt, decrypt, decrypt, encrypt, encrypt, encrypt, getBlockSize, getCipherMode, getMode, getPadding, init, initCipher, initDecrypt, initEncrypt, setKey, 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 |
|---|
public static final String DEFAULT_MODE
public static final String DEFAULT_PADDING
protected byte[] iv
protected AlgorithmParameterSpec paramSpec
| Constructor Detail |
|---|
protected SymmetricAlgorithm(String cipherAlgorithm,
String cipherModeName,
String cipherPadding)
cipherAlgorithm - Cipher algorithm name.cipherModeName - Cipher mode.cipherPadding - Cipher padding method.| Method Detail |
|---|
public static SymmetricAlgorithm newInstance(String cipherAlgorithm)
cipherAlgorithm - Cipher algorithm name.
public static SymmetricAlgorithm newInstance(AlgorithmSpec spec)
spec - Algorithm specification.
public static SymmetricAlgorithm newInstance(String cipherAlgorithm,
String cipherModeName,
String cipherPadding)
cipherAlgorithm - Cipher algorithm name.cipherModeName - Cipher mode.cipherPadding - Cipher padding method.
public static SymmetricAlgorithm newInstance(AlgorithmSpec spec,
AlgorithmParameterSpec cipherSpec)
spec - Algorithm specification.cipherSpec - Cipher-specific initialization parameters.
public static SecretKey generateKey(String algorithm,
int bitLength,
SecureRandom random)
throws CryptException
algorithm - Name of cipher algorithm for which a suitable key will
be generated.bitLength - Bit length required in generated key. Valid key lengths
are commonly a function of the cipher algorithm.random - Source of random data for key generation operation.
CryptException - if the private key cannot be generated
public SecretKey generateKey()
throws CryptException
CryptException - On key generation errors.
public SecretKey generateKey(int bitLength)
throws CryptException
bitLength - Bit length required in generated key. Valid key lengths
are commonly a function of the cipher algorithm.
CryptException - On key generation errors.public void setIV(byte[] ivBytes)
getRandomIV() method to obtain random initialization data of the
appropriate size for the chosen cipher.
IV data is used upon calling either AbstractEncryptionAlgorithm.initEncrypt() or AbstractEncryptionAlgorithm.initDecrypt().
ivBytes - Initialization bytes; in many cases the size of data
should be equal to the cipher block size.public boolean hasIV()
public byte[] getRandomIV()
AbstractEncryptionAlgorithm.getBlockSize().public int[] getAllowedKeyLengths()
public int getDefaultKeyLength()
public int getMinKeyLength()
public int getMaxKeyLength()
public boolean isValidKeyLength(int bitLength)
bitLength - Key size in bits.
protected AlgorithmParameterSpec getAlgorithmParameterSpec()
getAlgorithmParameterSpec in class AbstractEncryptionAlgorithmprotected int getChunkSize()
getChunkSize in class AbstractEncryptionAlgorithm
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||