JSS 3.1.2

org.mozilla.jss.pkcs11
Class PK11Cipher

java.lang.Object
  |
  +--org.mozilla.jss.crypto.Cipher
        |
        +--org.mozilla.jss.pkcs11.PK11Cipher

final class PK11Cipher
extends Cipher


Field Summary
private  EncryptionAlgorithm algorithm
           
private  CipherContextProxy contextProxy
           
private static int DECRYPT
           
private static int ENCRYPT
           
private  byte[] IV
           
private  SymmetricKey key
           
private  java.security.spec.AlgorithmParameterSpec parameters
           
private  int state
           
private  PK11Token token
           
private static int UNINITIALIZED
           
 
Constructor Summary
private PK11Cipher()
           
(package private) PK11Cipher(PK11Token token, EncryptionAlgorithm algorithm)
           
 
Method Summary
private  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(java.security.spec.AlgorithmParameterSpec params)
          Matches the params against those expected by the algorithm.
 byte[] doFinal()
          Completes an cipher operation.
 byte[] doFinal(byte[] bytes)
          Completes an cipher operation.
 byte[] doFinal(byte[] bytes, int offset, int length)
          Completes an cipher operation.
private static byte[] finalizeContext(CipherContextProxy context, int blocksize, boolean padded)
           
private static CipherContextProxy initContext(boolean encrypt, SymmetricKey key, EncryptionAlgorithm alg, byte[] IV)
           
 void initDecrypt(SymmetricKey key)
          Initializes a decryption context with a symmetric key.
 void initDecrypt(SymmetricKey key, java.security.spec.AlgorithmParameterSpec parameters)
          Initializes a decryption context with a symmetric key and algorithm parameters.
 void initEncrypt(SymmetricKey key)
          Initializes a encryption context with a symmetric key.
 void initEncrypt(SymmetricKey key, java.security.spec.AlgorithmParameterSpec parameters)
          Initializes an encryption context with a symmetric key and algorithm parameters.
private  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)
           
 
Methods inherited from class org.mozilla.jss.crypto.Cipher
pad, unPad, unPad
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

token

private PK11Token token

algorithm

private EncryptionAlgorithm algorithm

parameters

private java.security.spec.AlgorithmParameterSpec parameters

key

private SymmetricKey key

IV

private byte[] IV

contextProxy

private CipherContextProxy contextProxy

state

private int state

UNINITIALIZED

private static final int UNINITIALIZED

ENCRYPT

private static final int ENCRYPT

DECRYPT

private static final int DECRYPT
Constructor Detail

PK11Cipher

private PK11Cipher()

PK11Cipher

PK11Cipher(PK11Token token,
           EncryptionAlgorithm algorithm)
Method Detail

initEncrypt

public void initEncrypt(SymmetricKey key)
                 throws java.security.InvalidKeyException,
                        java.security.InvalidAlgorithmParameterException,
                        TokenException
Description copied from class: Cipher
Initializes a encryption context with a symmetric key.
Overrides:
initEncrypt in class Cipher

initDecrypt

public void initDecrypt(SymmetricKey key)
                 throws java.security.InvalidKeyException,
                        java.security.InvalidAlgorithmParameterException,
                        TokenException
Description copied from class: Cipher
Initializes a decryption context with a symmetric key.
Overrides:
initDecrypt in class Cipher

initEncrypt

public void initEncrypt(SymmetricKey key,
                        java.security.spec.AlgorithmParameterSpec parameters)
                 throws java.security.InvalidKeyException,
                        java.security.InvalidAlgorithmParameterException,
                        TokenException
Description copied from class: Cipher
Initializes an encryption context with a symmetric key and algorithm parameters.
Overrides:
initEncrypt in class Cipher

initDecrypt

public void initDecrypt(SymmetricKey key,
                        java.security.spec.AlgorithmParameterSpec parameters)
                 throws java.security.InvalidKeyException,
                        java.security.InvalidAlgorithmParameterException,
                        TokenException
Description copied from class: Cipher
Initializes a decryption context with a symmetric key and algorithm parameters.
Overrides:
initDecrypt in class Cipher

update

public byte[] update(byte[] bytes)
              throws java.lang.IllegalStateException,
                     TokenException
Description copied from class: Cipher
Updates the encryption context with additional input.
Overrides:
update in class Cipher
Following copied from class: org.mozilla.jss.crypto.Cipher
Parameters:
bytes - Bytes of plaintext (if encrypting) or ciphertext (if decrypting).
Returns:
Bytes of ciphertext (if encrypting) or plaintext (if decrypting).

update

public byte[] update(byte[] bytes,
                     int offset,
                     int length)
              throws java.lang.IllegalStateException,
                     TokenException
Description copied from class: Cipher
Updates the encryption context with additional plaintext.
Overrides:
update in class Cipher
Following copied from class: org.mozilla.jss.crypto.Cipher
Parameters:
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.
Returns:
Bytes of ciphertext (if encrypting) or plaintext (if decrypting).

doFinal

public byte[] doFinal(byte[] bytes)
               throws java.lang.IllegalStateException,
                      IllegalBlockSizeException,
                      BadPaddingException,
                      TokenException
Description copied from class: Cipher
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.
Overrides:
doFinal in class Cipher
Following copied from class: org.mozilla.jss.crypto.Cipher
Parameters:
bytes - Bytes of plaintext (if encrypting) or ciphertext (if decrypting).
Returns:
The last of the output.

doFinal

public byte[] doFinal(byte[] bytes,
                      int offset,
                      int length)
               throws java.lang.IllegalStateException,
                      IllegalBlockSizeException,
                      BadPaddingException,
                      TokenException
Description copied from class: Cipher
Completes an cipher operation.
Overrides:
doFinal in class Cipher
Following copied from class: org.mozilla.jss.crypto.Cipher
Parameters:
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.
Returns:
The last of the output.

doFinal

public byte[] doFinal()
               throws java.lang.IllegalStateException,
                      IllegalBlockSizeException,
                      BadPaddingException,
                      TokenException
Description copied from class: Cipher
Completes an cipher operation.
Overrides:
doFinal in class Cipher
Following copied from class: org.mozilla.jss.crypto.Cipher
Returns:
The last of the output.

initContext

private static CipherContextProxy initContext(boolean encrypt,
                                              SymmetricKey key,
                                              EncryptionAlgorithm alg,
                                              byte[] IV)
                                       throws TokenException

updateContext

private static byte[] updateContext(CipherContextProxy context,
                                    byte[] input,
                                    int blocksize)
                             throws TokenException

finalizeContext

private static byte[] finalizeContext(CipherContextProxy context,
                                      int blocksize,
                                      boolean padded)
                               throws TokenException,
                                      IllegalBlockSizeException,
                                      BadPaddingException

reset

private void reset()

checkParams

private void checkParams(java.security.spec.AlgorithmParameterSpec params)
                  throws java.security.InvalidAlgorithmParameterException
Matches the params against those expected by the algorithm.

checkKey

private void checkKey(SymmetricKey key)
               throws java.security.InvalidKeyException
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.

JSS 3.1.2