Package org.owasp.esapi.crypto
Class CipherSpec
- java.lang.Object
-
- org.owasp.esapi.crypto.CipherSpec
-
- All Implemented Interfaces:
java.io.Serializable
public final class CipherSpec extends java.lang.Object implements java.io.SerializableSpecifies all the relevant configuration data needed in constructing and using aCipherexcept for the encryption key.The "setters" all return a reference to
thisso 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.
- Since:
- 2.0
- Author:
- kevin.w.wall@gmail.com
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CipherSpec()Default CTOR.CipherSpec(byte[] iv)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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanEqual(java.lang.Object other)Needed for correct definition of equals for general classes.booleanequals(java.lang.Object other)intgetBlockSize()Retrieve the block size, in bytes.java.lang.StringgetCipherAlgorithm()Retrieve the cipher algorithm.java.lang.StringgetCipherMode()Retrieve the cipher mode.java.lang.StringgetCipherTransformation()Get the cipher transformation.byte[]getIV()Retrieve the initialization vector (IV).intgetKeySize()Retrieve the key size, in bits.java.lang.StringgetPaddingScheme()Retrieve the cipher padding scheme.inthashCode()booleanrequiresIV()Return true if the cipher mode requires an IV.CipherSpecsetBlockSize(int blockSize)Set the block size for thisCipherSpec.CipherSpecsetCipherTransformation(java.lang.String cipherXform)Set the cipher transformation for thisCipherSpec.CipherSpecsetIV(byte[] iv)Set the initialization vector (IV).CipherSpecsetKeySize(int keySize)Set the key size for thisCipherSpec.java.lang.StringtoString()OverrideObject.toString()to provide something more useful.
-
-
-
Constructor Detail
-
CipherSpec
public CipherSpec(java.lang.String cipherXform, int keySize, int blockSize, byte[] iv)CTOR that explicitly sets everything.- Parameters:
cipherXform- The cipher transformationkeySize- The key size (in bits).blockSize- The block size (in bytes).iv- The initialization vector. Null if not applicable.
-
CipherSpec
public CipherSpec(java.lang.String cipherXform, int keySize, int blockSize)CTOR that sets everything but IV.- Parameters:
cipherXform- The cipher transformationkeySize- The key size (in bits).blockSize- The block size (in bytes).
-
CipherSpec
public CipherSpec(java.lang.String cipherXform, int keySize)CTOR that sets everything but block size and IV.
-
CipherSpec
public CipherSpec(java.lang.String cipherXform, int keySize, byte[] iv)CTOR that sets everything except block size.
-
CipherSpec
public CipherSpec(javax.crypto.Cipher cipher)
CTOR that sets everything except for the cipher key size and possibly the IV. (IV may not be applicable--e.g., with ECB--or may not have been specified yet.
-
CipherSpec
public CipherSpec(javax.crypto.Cipher cipher, int keySize)CTOR that sets everything.
-
CipherSpec
public CipherSpec(byte[] iv)
-
CipherSpec
public CipherSpec()
Default CTOR. Creates a cipher specification for 128-bit cipher transformation of "AES/CBC/PKCS5Padding" and anullIV.
-
-
Method Detail
-
setCipherTransformation
public CipherSpec setCipherTransformation(java.lang.String cipherXform)
Set the cipher transformation for thisCipherSpec.- Parameters:
cipherXform- The cipher transformation string; e.g., "DESede/CBC/PKCS5Padding".- Returns:
- This current
CipherSpecobject.
-
getCipherTransformation
public java.lang.String getCipherTransformation()
Get the cipher transformation.- Returns:
- The cipher transformation
String.
-
setKeySize
public CipherSpec setKeySize(int keySize)
Set the key size for thisCipherSpec.- Parameters:
keySize- The key size, in bits. Must be positive integer.- Returns:
- This current
CipherSpecobject.
-
getKeySize
public int getKeySize()
Retrieve the key size, in bits.- Returns:
- The key size, in bits, is returned.
-
setBlockSize
public CipherSpec setBlockSize(int blockSize)
Set the block size for thisCipherSpec.- Parameters:
blockSize- The block size, in bytes. Must be positive integer appropriate for the specified cipher algorithm.- Returns:
- This current
CipherSpecobject.
-
getBlockSize
public int getBlockSize()
Retrieve the block size, in bytes.- Returns:
- The block size, in bytes, is returned.
-
getCipherAlgorithm
public java.lang.String getCipherAlgorithm()
Retrieve the cipher algorithm.- Returns:
- The cipher algorithm.
-
getCipherMode
public java.lang.String getCipherMode()
Retrieve the cipher mode.- Returns:
- The cipher mode.
-
getPaddingScheme
public java.lang.String getPaddingScheme()
Retrieve the cipher padding scheme.- Returns:
- The padding scheme is returned.
-
getIV
public byte[] getIV()
Retrieve the initialization vector (IV).- Returns:
- The IV as a byte array.
-
setIV
public CipherSpec setIV(byte[] iv)
Set the initialization vector (IV).- Parameters:
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.- Returns:
- This current
CipherSpecobject.
-
requiresIV
public boolean requiresIV()
Return true if the cipher mode requires an IV.- Returns:
- True if the cipher mode requires an IV, otherwise false.
-
toString
public java.lang.String toString()
OverrideObject.toString()to provide something more useful.- Overrides:
toStringin classjava.lang.Object- Returns:
- A meaningful string describing this object.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
canEqual
protected boolean canEqual(java.lang.Object other)
Needed for correct definition of equals for general classes. (Technically not needed for 'final' classes like this class though; this will just allow it to work in the future should we decide to allow sub-classing of this class.)See How to write an Equality Method in Java for full explanation.
-
-