public final class CipherSpec
extends java.lang.Object
implements java.io.Serializable
Cipher except for the encryption key.
The "setters" all return a reference to this so that they can be
strung together.
Note: While this is a useful class in it's own right, it should primarily be regarded as an implementation class to use with ESAPI encryption, especially the reference implementation. It is not intended to be used directly by application developers, but rather only by those either extending ESAPI or in the ESAPI reference implementation. Use directly by application code is not recommended or supported.
| Modifier and Type | Class and Description |
|---|---|
private static class |
CipherSpec.CipherTransformationComponent |
| Modifier and Type | Field and Description |
|---|---|
private int |
blockSize_ |
private java.lang.String |
cipher_xform_ |
private byte[] |
iv_ |
private int |
keySize_ |
private static long |
serialVersionUID |
| Constructor and Description |
|---|
CipherSpec()
Default CTOR.
|
CipherSpec(byte[] iv) |
CipherSpec(javax.crypto.Cipher cipher)
CTOR that sets everything except for the cipher key size and possibly
the IV.
|
CipherSpec(javax.crypto.Cipher cipher,
int keySize)
CTOR that sets everything.
|
CipherSpec(java.lang.String cipherXform,
int keySize)
CTOR that sets everything but block size and IV.
|
CipherSpec(java.lang.String cipherXform,
int keySize,
byte[] iv)
CTOR that sets everything except block size.
|
CipherSpec(java.lang.String cipherXform,
int keySize,
int blockSize)
CTOR that sets everything but IV.
|
CipherSpec(java.lang.String cipherXform,
int keySize,
int blockSize,
byte[] iv)
CTOR that explicitly sets everything.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
canEqual(java.lang.Object other)
Needed for correct definition of equals for general classes.
|
boolean |
equals(java.lang.Object other) |
int |
getBlockSize()
Retrieve the block size, in bytes.
|
java.lang.String |
getCipherAlgorithm()
Retrieve the cipher algorithm.
|
java.lang.String |
getCipherMode()
Retrieve the cipher mode.
|
java.lang.String |
getCipherTransformation()
Get the cipher transformation.
|
private java.lang.String |
getFromCipherXform(CipherSpec.CipherTransformationComponent component)
Split the current cipher transformation and return the requested part.
|
byte[] |
getIV()
Retrieve the initialization vector (IV).
|
int |
getKeySize()
Retrieve the key size, in bits.
|
java.lang.String |
getPaddingScheme()
Retrieve the cipher padding scheme.
|
int |
hashCode() |
boolean |
requiresIV()
Return true if the cipher mode requires an IV.
|
CipherSpec |
setBlockSize(int blockSize)
Set the block size for this
CipherSpec. |
CipherSpec |
setCipherTransformation(java.lang.String cipherXform)
Set the cipher transformation for this
CipherSpec. |
private CipherSpec |
setCipherTransformation(java.lang.String cipherXform,
boolean fromCipher)
Set the cipher transformation for this
CipherSpec. |
CipherSpec |
setIV(byte[] iv)
Set the initialization vector (IV).
|
CipherSpec |
setKeySize(int keySize)
Set the key size for this
CipherSpec. |
java.lang.String |
toString()
Override
Object.toString() to provide something more useful. |
private static final long serialVersionUID
private java.lang.String cipher_xform_
private int keySize_
private int blockSize_
private byte[] iv_
public CipherSpec(java.lang.String cipherXform,
int keySize,
int blockSize,
byte[] iv)
cipherXform - The cipher transformationkeySize - The key size (in bits).blockSize - The block size (in bytes).iv - The initialization vector. Null if not applicable.public CipherSpec(java.lang.String cipherXform,
int keySize,
int blockSize)
cipherXform - The cipher transformationkeySize - The key size (in bits).blockSize - The block size (in bytes).public CipherSpec(java.lang.String cipherXform,
int keySize)
public CipherSpec(java.lang.String cipherXform,
int keySize,
byte[] iv)
public CipherSpec(javax.crypto.Cipher cipher)
public CipherSpec(javax.crypto.Cipher cipher,
int keySize)
public CipherSpec(byte[] iv)
public CipherSpec()
null IV.public CipherSpec setCipherTransformation(java.lang.String cipherXform)
CipherSpec.cipherXform - The cipher transformation string; e.g., "DESede/CBC/PKCS5Padding".CipherSpec object.private CipherSpec setCipherTransformation(java.lang.String cipherXform, boolean fromCipher)
CipherSpec. This is only
used by the CTOR CipherSpec(Cipher) and CipherSpec(Cipher, int).cipherXform - The cipher transformation string; e.g.,
"DESede/CBC/PKCS5Padding". May not be null or empty.fromCipher - If true, the cipher transformation was set via
Cipher.getAlgorithm() which may only return the
actual algorithm. In that case we check and if all 3 parts
were not specified, then we specify the parts that were
based on "ECB" as the default cipher mode and "NoPadding"
as the default padding scheme.CipherSpec object.public java.lang.String getCipherTransformation()
String.public CipherSpec setKeySize(int keySize)
CipherSpec.keySize - The key size, in bits. Must be positive integer.CipherSpec object.public int getKeySize()
public CipherSpec setBlockSize(int blockSize)
CipherSpec.blockSize - The block size, in bytes. Must be positive integer.CipherSpec object.public int getBlockSize()
public java.lang.String getCipherAlgorithm()
public java.lang.String getCipherMode()
public java.lang.String getPaddingScheme()
public byte[] getIV()
public CipherSpec setIV(byte[] iv)
iv - The byte array to set as the IV. A copy of the IV is saved.
This parameter is ignored if the cipher mode does not
require an IV.CipherSpec object.public boolean requiresIV()
public java.lang.String toString()
Object.toString() to provide something more useful.toString in class java.lang.Objectpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectprotected boolean canEqual(java.lang.Object other)
See How to write an Equality Method in Java for full explanation.
private java.lang.String getFromCipherXform(CipherSpec.CipherTransformationComponent component)
component - The component of the cipher transformation to return.