A context for performing symmetric encryption and decryption.
First, the context must be initialized. Then, it can be updated
with input through zero or more calls to update
. Finally,
doFinal
is called to finalize the operation. Note that
it is not necessary to call update
if all of the data is
available at once. In this case, all of the input can be processed with one
call to doFinal
.
doFinal
public abstract byte[] doFinal(byte[] bytes)
throws IllegalStateException,
IllegalBlockSizeException,
BadPaddingException,
TokenException
Completes an cipher operation. This can be called directly after
the context is initialized, or update
may be called
any number of times before calling final
.
bytes
- Bytes of plaintext (if encrypting) or ciphertext (if
decrypting).
doFinal
public abstract byte[] doFinal(byte[] bytes,
int offset,
int length)
throws IllegalStateException,
IllegalBlockSizeException,
BadPaddingException,
TokenException
Completes an cipher operation.
bytes
- Bytes of plaintext (if encrypting) or ciphertext (if
decrypting).offset
- The index in bytes
at which to begin reading.length
- The number of bytes from bytes
to read.
initDecrypt
public abstract void initDecrypt(SymmetricKey key)
throws InvalidKeyException,
InvalidAlgorithmParameterException,
TokenException
Initializes a decryption context with a symmetric key.
initDecrypt
public abstract void initDecrypt(SymmetricKey key,
AlgorithmParameterSpec parameters)
throws InvalidKeyException,
InvalidAlgorithmParameterException,
TokenException
Initializes a decryption context with a symmetric key and
algorithm parameters.
initEncrypt
public abstract void initEncrypt(SymmetricKey key)
throws InvalidKeyException,
InvalidAlgorithmParameterException,
TokenException
Initializes a encryption context with a symmetric key.
initEncrypt
public abstract void initEncrypt(SymmetricKey key,
AlgorithmParameterSpec parameters)
throws InvalidKeyException,
InvalidAlgorithmParameterException,
TokenException
Initializes an encryption context with a symmetric key and
algorithm parameters.
pad
public static byte[] pad(byte[] toBePadded,
int blockSize)
Pads a byte array so that its length is a multiple of the given
blocksize. The method of padding is the one defined in the RSA
PKCS standards. If M is the length of the data and
B is the block size, the padding string consists of
B - (M mod B) octets, each having the value
B - (M mod B).
unPad
public static byte[] unPad(byte[] padded)
throws BadPaddingException
Un-pads a byte array that is padded with PKCS padding. Since
this version does not take block size as a parameter, it cannot
error check.
unPad
public static byte[] unPad(byte[] padded,
int blockSize)
throws BadPaddingException
Un-pads a byte array that is padded with PKCS padding.
blockSize
- The block size of the encryption algorithm. This
is only used for error checking: if the pad size is not
between 1 and blockSize, a BadPaddingException is thrown.
update
public abstract byte[] update(byte[] bytes)
throws IllegalStateException,
TokenException
Updates the encryption context with additional input.
bytes
- Bytes of plaintext (if encrypting) or ciphertext (if
decrypting).
- Bytes of ciphertext (if encrypting) or plaintext (if decrypting).
update
public abstract byte[] update(byte[] bytes,
int offset,
int length)
throws IllegalStateException,
TokenException
Updates the encryption context with additional plaintext.
bytes
- Bytes of plaintext (if encrypting) or ciphertext (if
decrypting).offset
- The index in bytes
at which to begin reading.length
- The number of bytes from bytes
to read.
- Bytes of ciphertext (if encrypting) or plaintext (if decrypting).