public class CkiSymmetricCipher
extends BlockCipher
Constructor and Description |
---|
CkiSymmetricCipher()
Empty constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
algName()
Returns the name of the algorithm used by this Symmetric Cipher object.
|
byte[] |
decrypt(byte[] bytes) |
byte[] |
decrypt(byte[] bytes, int offset, int length, boolean unpad)
Decrypts a sequence of bytes of specified length and, if specified, removes padding.
|
void |
decrypt(byte[] in, int inOff, int inLen, byte[] out, int outOff)
Decrypt an array of bytes.
|
void |
decryptBlock(byte[] in, int inOff, byte[] out, int outOff) |
void |
decryptOp(byte[] in, int inOff, byte[] out, int outOff)
Deprecated.
|
byte[] |
encrypt(byte[] bytes) |
byte[] |
encrypt(byte[] bytes, int offset, int length, boolean pad)
Encrypts a sequence of bytes of specified length and, if specified, performs padding.
|
void |
encrypt(byte[] in, int inOff, int inLen, byte[] out, int outOff)
Encrypt an array of bytes.
|
void |
encryptBlock(byte[] in, int inOff, byte[] out, int outOff) |
void |
encryptOp(byte[] in, int inOff, byte[] out, int outOff)
Deprecated.
|
void |
erase()
Erases the keys and the sensitive data of this
CkiSymmetricCipher object. |
protected void |
finalize() |
AlgorithmIdentifier |
getAlgID()
Returns the AlgorithmIdentifier used by this object.
|
static long |
getBlockSize(AlgorithmIdentifier algID)
Returns the blocksize of a symmetric cipher given the algID
|
static long |
getCkiMechanismID(AlgorithmIdentifier algID)
Returns the Cryptoki mechanism type given the algID parameter.
|
static long |
getCkiObjectID(AlgorithmIdentifier algID)
Returns the Cryptoki key type given the algID parameter.
|
int |
getEffectiveKeyLength()
Returns the effective key length.
|
void |
initialize(AlgorithmIdentifier algID, Key key)
This method verifies the AlgorithmIdentifier's Object ID and configures the CkiSymmetricCipher instance appropriately with the params of the AlgorithmIdentifier in addition to the Key.
|
void |
initialize(AlgorithmIdentifier algID, SymmetricKey key, Padding.ID paddingID)
This method may be used to initialize the CkiSymmetricCipher instance for use.
|
void |
setAlgID(AlgorithmIdentifier algID)
Deprecated.
|
void |
setDecryptionKey(Key key)
Deprecated.
|
void |
setEffectiveKeyLength(int len)
Sets the effective key length.
|
void |
setEncryptionKey(Key key)
Deprecated.
|
void |
setIV(byte[] iv)
Deprecated.
|
void |
setKey(SymmetricKey userKey)
Deprecated.
|
void |
setSession(CkiMgtSession session)
Sets the CkiMgtSession to use.
|
public CkiSymmetricCipher()
public void initialize(AlgorithmIdentifier algID, Key key) throws AlgorithmIdentifierException, InvalidKeyException, CipherException
algID
- is the AlgorithmIdentifier whose params will be used to configure the cipher.key
- is the Key instance that will be cloned and used by the cipher internally. This instance will be erased when the Cipher.erase()
is called.AlgorithmIdentifierException
- is thrown 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
- is thrown if there is a problem with the Key instance the Cipher is being initialized with.CipherException
- is thrown if the op argument is null.public void initialize(AlgorithmIdentifier algID, SymmetricKey key, Padding.ID paddingID) throws AlgorithmIdentifierException, InvalidKeyException, CipherException
algID
- is the AlgorithmIdentifier whose params will be used to configure the cipher.key
- is the Key instance that will be cloned and used by the cipher internally. This instance will be erased when the Cipher.erase()
is called.paddingID
- is used to indicate the type of padding that the Cipher should use. Options are Padding.NONE or Padding.PKCS5. A Cipher must be re-initialized before being used with the other Padding type.AlgorithmIdentifierException
- is thrown 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
- is thrown if there is a problem with the Key instance the Cipher is being initialized with.CipherException
- is thrown if there is a problem initializing the Cipher.public void setSession(CkiMgtSession session)
public void setAlgID(AlgorithmIdentifier algID) throws AlgorithmIdentifierException
AlgorithmIdentifierException
public AlgorithmIdentifier getAlgID()
public java.lang.String algName()
public byte[] encrypt(byte[] bytes) throws CipherException
CipherException
public byte[] encrypt(byte[] bytes, int offset, int length, boolean pad) throws CipherException
bytes
- Buffer in which data to be encrypted is stored.offset
- Offset within buffer of the start of the data.length
- The length of the data.pad
- True if padding is to be used, false otherwise.CipherException
- if cipher not initialized, data is not a multiple of the block size and no padding is specified, etc.public void encrypt(byte[] in, int inOff, int inLen, byte[] out, int outOff) throws CipherException
in
- array of bytes to be encryptedinOff
- offset of the start of datainLen
- the length of the dataout
- array to place the encrypted bytesoutOff
- offset of the start of the encrypted bytesCipherException
- thrown if cipher not initialized, block size incorrect, etc.public void encryptBlock(byte[] in, int inOff, byte[] out, int outOff) throws CipherException
CipherException
public void encryptOp(byte[] in, int inOff, byte[] out, int outOff) throws CipherException
in
- buffer in which data to be encrypted is storedinOff
- offset within input buffer of the start of dataout
- buffer to place the encrypted bytes inoutOff
- offset within output buffer where the encrypted bytes will be storedCipherException
- if cipher not initialized, length of data is not equal to the block size, etc.public byte[] decrypt(byte[] bytes) throws CipherException
CipherException
public byte[] decrypt(byte[] bytes, int offset, int length, boolean unpad) throws CipherException
bytes
- Buffer in which data to be decrypted is stored.offset
- Offset within buffer of the start of data.length
- The length of the dataunpad
- True if padding is to be removed, false otherwiseCipherException
- if cipher not initialized, data is not a multiple of the block size and no padding is specified, etc.public void decrypt(byte[] in, int inOff, int inLen, byte[] out, int outOff) throws CipherException
in
- array of bytes to be decryptedinOff
- offset of the start of datainLen
- the length of the dataout
- array to place the decrypted bytesoutOff
- offset of the start of the decrypted bytesCipherException
- thrown if cipher not initialized, block size incorrect, etc.public void decryptBlock(byte[] in, int inOff, byte[] out, int outOff) throws CipherException
CipherException
public void decryptOp(byte[] in, int inOff, byte[] out, int outOff) throws CipherException
in
- Buffer in which data to be decrypted is stored.inOff
- Offset within input buffer of the start of data.out
- Buffer to place the decrypted bytes inoutOff
- Offset within output buffer where the encrypted bytes will be stored.CipherException
- thrown if cipher not initialized, length of data is not equal to the block size, etc.public void setIV(byte[] iv) throws CipherException
iv
- the IVCipherException
public void setEffectiveKeyLength(int len) throws CipherException
setKey
, otherwise the default value will be used.len
- the effective key length in bits.CipherException
public int getEffectiveKeyLength()
public void setKey(SymmetricKey userKey) throws InvalidKeyException
The algorithm-specified key expansion is performed at this time.
InvalidKeyException
public void setEncryptionKey(Key key) throws InvalidKeyException
InvalidKeyException
public void setDecryptionKey(Key key) throws InvalidKeyException
InvalidKeyException
public static long getCkiObjectID(AlgorithmIdentifier algID)
algID
- The algorithm identifier of the symmetric key.public static long getCkiMechanismID(AlgorithmIdentifier algID)
algID
- The algorithm identifier of the symmetric cipher.public static long getBlockSize(AlgorithmIdentifier algID)
public void erase()
CkiSymmetricCipher
object.protected void finalize()