Package org.mozilla.jss.pkcs11
Class PK11Cipher
java.lang.Object
org.mozilla.jss.crypto.Cipher
org.mozilla.jss.pkcs11.PK11Cipher
- All Implemented Interfaces:
AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate EncryptionAlgorithm
private CipherContextProxy
private static final int
private static final int
private byte[]
private SymmetricKey
private AlgorithmParameterSpec
private int
private PK11Token
private static final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
(package private)
PK11Cipher
(PK11Token token, EncryptionAlgorithm algorithm) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkKey
(SymmetricKey key) Checks for null, makes sure the key lives on the correct token, makes sure it is a PKCS #11 key, makes sure it's the right type for this algorithm.private void
checkParams
(AlgorithmParameterSpec params) Matches the params against those expected by the algorithm.void
close()
byte[]
doFinal()
Deprecated.isPadded() in EncryptionAlgorithm has been deprecatedbyte[]
doFinal
(byte[] bytes) Deprecated.isPadded() in EncryptionAlgorithm has been deprecatedbyte[]
doFinal
(byte[] bytes, int offset, int length) Completes an cipher operation.void
finalize()
private static byte[]
finalizeContext
(CipherContextProxy context, int blocksize, boolean padded) private static byte[]
private static CipherContextProxy
initContext
(boolean encrypt, SymmetricKey key, EncryptionAlgorithm alg, byte[] IV, boolean padded) private static CipherContextProxy
initContextWithKeyBits
(boolean encrypt, SymmetricKey key, EncryptionAlgorithm alg, byte[] IV, int keyBits, boolean padded) void
initDecrypt
(SymmetricKey key) Initializes a decryption context with a symmetric key.void
initDecrypt
(SymmetricKey key, AlgorithmParameterSpec parameters) Deprecated.isPadded() in EncryptionAlgorithm has been deprecatedvoid
initEncrypt
(SymmetricKey key) Initializes a encryption context with a symmetric key.void
initEncrypt
(SymmetricKey key, AlgorithmParameterSpec parameters) Deprecated.isPadded() in EncryptionAlgorithm has been deprecatedprivate void
reset()
byte[]
update
(byte[] bytes) Updates the encryption context with additional input.byte[]
update
(byte[] bytes, int offset, int length) Updates the encryption context with additional plaintext.private static byte[]
updateContext
(CipherContextProxy context, byte[] input, int blocksize)
-
Field Details
-
token
-
algorithm
-
parameters
-
key
-
IV
private byte[] IV -
contextProxy
-
state
private int state -
UNINITIALIZED
private static final int UNINITIALIZED- See Also:
-
ENCRYPT
private static final int ENCRYPT- See Also:
-
DECRYPT
private static final int DECRYPT- See Also:
-
-
Constructor Details
-
PK11Cipher
private PK11Cipher() -
PK11Cipher
PK11Cipher(PK11Token token, EncryptionAlgorithm algorithm)
-
-
Method Details
-
initEncrypt
public void initEncrypt(SymmetricKey key) throws InvalidKeyException, InvalidAlgorithmParameterException, TokenException Description copied from class:Cipher
Initializes a encryption context with a symmetric key.- Specified by:
initEncrypt
in classCipher
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
TokenException
-
initDecrypt
public void initDecrypt(SymmetricKey key) throws InvalidKeyException, InvalidAlgorithmParameterException, TokenException Description copied from class:Cipher
Initializes a decryption context with a symmetric key.- Specified by:
initDecrypt
in classCipher
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
TokenException
-
getIVFromParams
-
initEncrypt
@Deprecated public void initEncrypt(SymmetricKey key, AlgorithmParameterSpec parameters) throws InvalidKeyException, InvalidAlgorithmParameterException, TokenException Deprecated.isPadded() in EncryptionAlgorithm has been deprecatedDescription copied from class:Cipher
Initializes an encryption context with a symmetric key and algorithm parameters.- Specified by:
initEncrypt
in classCipher
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
TokenException
-
initDecrypt
@Deprecated public void initDecrypt(SymmetricKey key, AlgorithmParameterSpec parameters) throws InvalidKeyException, InvalidAlgorithmParameterException, TokenException Deprecated.isPadded() in EncryptionAlgorithm has been deprecatedDescription copied from class:Cipher
Initializes a decryption context with a symmetric key and algorithm parameters.- Specified by:
initDecrypt
in classCipher
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
TokenException
-
update
Description copied from class:Cipher
Updates the encryption context with additional input.- Specified by:
update
in classCipher
- Parameters:
bytes
- Bytes of plaintext (if encrypting) or ciphertext (if decrypting).- Returns:
- Bytes of ciphertext (if encrypting) or plaintext (if decrypting).
- Throws:
IllegalStateException
TokenException
-
update
public byte[] update(byte[] bytes, int offset, int length) throws IllegalStateException, TokenException Description copied from class:Cipher
Updates the encryption context with additional plaintext.- Specified by:
update
in classCipher
- Parameters:
bytes
- Bytes of plaintext (if encrypting) or ciphertext (if decrypting).offset
- The index inbytes
at which to begin reading.length
- The number of bytes frombytes
to read.- Returns:
- Bytes of ciphertext (if encrypting) or plaintext (if decrypting).
- Throws:
IllegalStateException
TokenException
-
doFinal
@Deprecated public byte[] doFinal(byte[] bytes) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException, TokenException Deprecated.isPadded() in EncryptionAlgorithm has been deprecatedDescription copied from class:Cipher
Completes an cipher operation. This can be called directly after the context is initialized, orupdate
may be called any number of times before callingfinal
.- Specified by:
doFinal
in classCipher
- Parameters:
bytes
- Bytes of plaintext (if encrypting) or ciphertext (if decrypting).- Returns:
- The last of the output.
- Throws:
IllegalStateException
IllegalBlockSizeException
BadPaddingException
TokenException
-
doFinal
public byte[] doFinal(byte[] bytes, int offset, int length) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException, TokenException Description copied from class:Cipher
Completes an cipher operation.- Specified by:
doFinal
in classCipher
- Parameters:
bytes
- Bytes of plaintext (if encrypting) or ciphertext (if decrypting).offset
- The index inbytes
at which to begin reading.length
- The number of bytes frombytes
to read.- Returns:
- The last of the output.
- Throws:
IllegalStateException
IllegalBlockSizeException
BadPaddingException
TokenException
-
doFinal
@Deprecated public byte[] doFinal() throws IllegalStateException, IllegalBlockSizeException, BadPaddingException, TokenExceptionDeprecated.isPadded() in EncryptionAlgorithm has been deprecatedDescription copied from class:Cipher
Completes an cipher operation.- Specified by:
doFinal
in classCipher
- Returns:
- The last of the output.
- Throws:
IllegalStateException
IllegalBlockSizeException
BadPaddingException
TokenException
-
initContext
private static CipherContextProxy initContext(boolean encrypt, SymmetricKey key, EncryptionAlgorithm alg, byte[] IV, boolean padded) throws TokenException - Throws:
TokenException
-
initContextWithKeyBits
private static CipherContextProxy initContextWithKeyBits(boolean encrypt, SymmetricKey key, EncryptionAlgorithm alg, byte[] IV, int keyBits, boolean padded) throws TokenException - Throws:
TokenException
-
updateContext
private static byte[] updateContext(CipherContextProxy context, byte[] input, int blocksize) throws TokenException - Throws:
TokenException
-
finalizeContext
private static byte[] finalizeContext(CipherContextProxy context, int blocksize, boolean padded) throws TokenException, IllegalBlockSizeException, BadPaddingException -
reset
private void reset() -
checkParams
Matches the params against those expected by the algorithm. -
checkKey
Checks for null, makes sure the key lives on the correct token, makes sure it is a PKCS #11 key, makes sure it's the right type for this algorithm.- Throws:
InvalidKeyException
-
finalize
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-