| Modifier and Type | Field and Description |
|---|---|
protected int |
blockSize
Block size of the wrapping BlockCipher.
|
protected byte[] |
iv
Initialization vector that the current processes are based off of (equivalent to the old iv from Cipher), for use in CBC mode.
|
protected Padding.ID |
paddingID
Holds the padding constant that will be used to determine the algorithm for to padding and unpadding data.
|
| Modifier | Constructor and Description |
|---|---|
protected |
BlockCipher()
Instantiates the BlockCipher with no block size.
|
protected |
BlockCipher(int blockSize)
Instantiates the BlockCipher with the block size of the actual instance.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decrypt(byte[] input, int inOff, int len, boolean unpad)
Decrypts a sequence of bytes of specified length, and, if specified, returns the unpadded plaintext.
|
void |
decrypt(byte[] input, int inOff, int len, byte[] output, int outOff)
Decrypts a sequence of bytes of specified length and places the original plaintext message in the given output buffer starting at the given offset.
|
protected abstract void |
decryptBlock(byte[] input, int inOff, byte[] output, int outOff)
Performs the block cipher's basic decryption operation on one block of ciphertext placing the result in the output buffer.
|
byte[] |
encrypt(byte[] input, int inOff, int len, boolean pad)
Encrypts a sequence of bytes of specified length and, if specified, performs padding.
|
void |
encrypt(byte[] input, int inOff, int len, byte[] output, int outOff)
Encrypts a sequence of bytes of specified length and places the resulting ciphertext in the given output buffer starting at the given offset.
|
protected abstract void |
encryptBlock(byte[] input, int inOff, byte[] output, int outOff)
Performs the block cipher's basic encryption operation on one block of plaintext placing the result in the output buffer.
|
void |
erase()
Erases any sensitive information stored in this BlockCipher object.
|
int |
getBlockSize()
Returns the block size of the cipher.
|
byte[] |
getIV()
Returns a clone of the initialization vector or null, if the IV is null.
|
Padding.ID |
getPaddingID()
Returns the Padding.ID constant value for this instance.
|
void |
initialize(AlgorithmIdentifier algID, Key key, RandomBitsSource rbs)
This method verifies the AlgorithmIdentifier's Object ID and configures the DES instance appropriately with the params of the AlgorithmIdentifier in addition to the Key.
|
protected void |
setIV(byte[] iv)
Sets the initialization vector for this block cipher.
|
PrivateKey |
unwrapPrivateKey(byte[] encKey)
Unwraps a private key using this cipher.
|
SymmetricKey |
unwrapSymmetricKey(byte[] encKey, AlgorithmIdentifier algID)
Unwraps a symmetric key using this cipher.
|
byte[] |
wrapKey(PrivateKey key)
Wraps a private key using this cipher.
|
byte[] |
wrapKey(SymmetricKey key)
Wraps a symmetric key using this cipher.
|
assertDecryption, assertEncryption, assertKeyUnwrap, assertKeyWrap, cloneKey, decodeOp, decrypt, decrypt, decrypt, encodeOp, encrypt, encrypt, encrypt, finalize, getAlgID, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getMode, initialize, initialize, initialize, releaseOpprotected byte[] iv
protected int blockSize
protected Padding.ID paddingID
protected BlockCipher()
AES.
By default, a BlockCipher is instantiated with mode of Cipher.ECB and padding scheme of Padding.NONE
protected BlockCipher(int blockSize)
By default, a BlockCipher is instantiated with mode of Cipher.ECB and padding scheme of Padding.NONE
public void initialize(AlgorithmIdentifier algID, Key key, RandomBitsSource rbs) throws AlgorithmIdentifierException, InvalidKeyException
initialize in class CipheralgID - The AlgorithmIdentifier whose params will be used to configure the cipher.key - The SymmetricKey instance that will be used by the cipher internally.rbs - The RandomBitsSourfce to use in this cipherAlgorithmIdentifierException - If the algID's OID isn't valid for the Cipher instance being initialized or if the params are not valid for the algID's OID.InvalidKeyException - If there is a problem with the Key instance the Cipher is being initialized with.
public byte[] decrypt(byte[] input,
int inOff,
int len,
boolean unpad)
throws CipherException
Cipherdecrypt in class Cipherinput - The buffer in which data to be decrypted is stored.inOff - The offset within buffer of the start of data.len - The length of the data.unpad - Specifies whether the plaintext should have padding removed.CipherException - If the Cipher was not initialized, if the Cipher was used for encryption without being re-initialized, if the data is not a multiple of the block size and no padding is specified, or if an error occurred during the decryption process.
public void decrypt(byte[] input,
int inOff,
int len,
byte[] output,
int outOff)
throws CipherException
Cipherdecrypt in class Cipherinput - The buffer in which data to be decrypted is stored.inOff - The offset within buffer of the start of data.len - The length of the data.output - The array to place the decrypted bytes.outOff - The offset of the start of the decrypted bytes.CipherException - If the Cipher was not initialized, if the Cipher was used for encryption without being re-initialized, if the data is not a multiple of the block size, or if an error occurred during the decryption process.
protected abstract void decryptBlock(byte[] input,
int inOff,
byte[] output,
int outOff)
throws CipherException
input - Buffer in which data to be decrypted is stored.inOff - Offset within input buffer of the start of data.output - Buffer to place the decrypted bytes inoutOff - Offset within output buffer where the encrypted bytes will be stored.CipherException - If the Cipher is not initialized, length of data is not equal to the block size, etc.
public byte[] encrypt(byte[] input,
int inOff,
int len,
boolean pad)
throws CipherException
Cipherencrypt in class Cipherinput - The buffer in which data to be encrypted is stored.inOff - The offset within buffer of the start of the data.len - The length of the data.pad - true if padding is to be used, false otherwise.CipherException - If the Cipher was not initialized, if the Cipher was used for decryption without being re-initialized, if the data is not a multiple of the block size and no padding is specified, or if an error occurred during the encryption process.
public void encrypt(byte[] input,
int inOff,
int len,
byte[] output,
int outOff)
throws CipherException
Cipherencrypt in class Cipherinput - The array of bytes to encrypt.inOff - The offset of the start of data to encrypt.len - The length of the data to encrypt.output - The array to place the encrypted bytes.outOff - The offset of the start of the encrypted bytes.CipherException - If the Cipher was not initialized, if the Cipher was used for decryption without being re-initialized, if the data is not a multiple of the block size, or if an error occurred during the encryption process.
protected abstract void encryptBlock(byte[] input,
int inOff,
byte[] output,
int outOff)
throws CipherException
input - Buffer in which data to be encrypted is storedinOff - Offset within input buffer of the start of dataoutput - Buffer to place the encrypted bytes inoutOff - Offset within output buffer where the encrypted bytes will be storedCipherException - If the Cipher is not initialized, length of data is not equal to the block size, etc.public byte[] wrapKey(PrivateKey key) throws CipherException
wrapKey in class Cipherkey - The private key to wrap.CipherException - If the Cipher was not initialized, if the Cipher was used for wrapping without being re-initialized or if an error occurred during the wrapping process.public byte[] wrapKey(SymmetricKey key) throws CipherException
wrapKey in class Cipherkey - The symmetric key to wrap.CipherException - If the Cipher was not initialized, if the Cipher was used for wrapping without being re-initialized or if an error occurred during the wrapping process.public PrivateKey unwrapPrivateKey(byte[] encKey) throws CipherException
unwrapPrivateKey in class CipherencKey - The encrypted key.If - the Cipher was not initialized, if the Cipher was used for wrapping without being re-initialized, if the key is not a private key or if an error occurred during the wrapping process.CipherException - If the Cipher was not initialized, if the Cipher was used for unwrapping without being re-initialized or if an error occurred during the decryption process.public SymmetricKey unwrapSymmetricKey(byte[] encKey, AlgorithmIdentifier algID) throws CipherException
unwrapSymmetricKey in class CipherencKey - The encrypted key.algID - The algorithm identifier of the wrapped symmetric key.CipherException - If the Cipher was not initialized, if the Cipher was used for unwrapping without being re-initialized or if an error occurred during the encryption process.public void erase()
public final int getBlockSize()
getBlockSize in class Cipherpublic final byte[] getIV()
protected void setIV(byte[] iv)
throws CipherException
iv - The new IV to set.CipherExceptionpublic final Padding.ID getPaddingID()
getPaddingID in class CipherPadding.ID