|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.rsa.jsafe.JSAFE_Object
com.rsa.jsafe.JSAFE_SymmetricCipher
This class defines the factory methods and API for all symmetric cipher objects. This is the actual encryption object; it does not perform key management or creation.
See Overview of Crypto-J for background and reference material on using and understanding Crypto-J.
Copyright © RSA Security Inc., 1997-2005. All rights reserved.
| Constructor Summary | |
JSAFE_SymmetricCipher()
|
|
| Method Summary | |
void |
clearSensitiveData()
This method clears sensitive data from an object. |
byte[] |
decryptFinal()
Finalizes the decryption process and strips any padding. |
abstract int |
decryptFinal(byte[] partOut,
int offset)
Finalizes the decryption process and strips any padding. |
void |
decryptInit(JSAFE_SecretKey key)
Initializes this object to decrypt using |
abstract void |
decryptInit(JSAFE_SecretKey key,
SecureRandom random)
This method initializes an object to perform decryption with
|
abstract void |
decryptReInit()
Re-initializes this object to decrypt using the key passed in during
an earlier call to |
byte[] |
decryptUpdate(byte[] partIn,
int offset,
int partInLen)
Decrypts the first |
abstract int |
decryptUpdate(byte[] partIn,
int inOffset,
int partInLen,
byte[] partOut,
int outOffset)
Decrypts the first |
byte[] |
encryptFinal()
This method finalizes the encryption process by encrypting any leftover bytes and padding (if padding is requested). |
abstract int |
encryptFinal(byte[] partOut,
int offset)
This method finalizes the encryption process by encrypting any leftover bytes and padding (if padding is requested). |
void |
encryptInit(JSAFE_SecretKey key)
Initializes an object to perform encryption with |
abstract void |
encryptInit(JSAFE_SecretKey key,
SecureRandom random)
Initializes this object to encrypt, using |
abstract void |
encryptReInit()
Re-initializes this object to encrypt using the key passed in during
an earlier call to the |
byte[] |
encryptUpdate(byte[] partIn,
int offset,
int partInLen)
Encrypts the first |
abstract int |
encryptUpdate(byte[] partIn,
int inOffset,
int partInLen,
byte[] partOut,
int outOffset)
Encrypts the first |
void |
generateIV(SecureRandom random)
Generates an initialization vector using |
void |
generateSalt(SecureRandom random)
Generates an 8-byte salt for PBE using |
abstract int[] |
getAlgorithmParameters()
Returns a new |
getBlankKey()
Returns an empty |
|
int |
getBlockSize()
Returns the size, in bytes, of the blocks on which an object operates. |
abstract byte[] |
getDERAlgorithmID()
Returns a new |
getDevice()
Returns the name of the device of record. |
|
String[] |
getDeviceList()
Returns a |
getDigestAlgorithm()
Returns the standard name of the digest algorithm used for PBE. |
|
abstract String |
getEncryptionAlgorithm()
Returns the standard name of the encryption algorithm. |
getFeedbackMode()
Returns the standard feedback mode name. |
|
int[] |
getFeedbackParameters()
Returns a new |
static JSAFE_SymmetricCipher |
getInstance(byte[] berAlgID,
int offset,
String device)
Builds an object that performs an algorithm using the
possible parameters defined in |
static JSAFE_SymmetricCipher |
getInstance(String transformation,
String device)
Builds an object that performs the |
byte[] |
getIV()
Returns the initialization vector (IV) in a new |
static int |
getNextBEROffset(byte[] berAlgID,
int offset)
Gets the next offset after the algorithm ID. |
abstract int |
getOutputBufferSize(int inputLen)
Returns the maximum size (in bytes) that an output buffer should be
to hold the results of a symmetric cipher processing
( |
int[] |
getPaddingParameters()
Returns a new |
getPaddingScheme()
Returns the standard padding scheme name. |
|
getPasswordStandard()
Returns the standard name of the PBE standard. |
|
int[] |
getPBEParameters()
Returns a new |
byte[] |
getSalt()
Returns the salt in a new |
abstract void |
setAlgorithmParameters(int[] params)
Sets this object to possess the algorithm parameters given. |
void |
setIV(byte[] iv,
int offset,
int ivLen)
Sets the IV to the first |
void |
setPBEParameters(int[] params)
Sets this object to possess the PBE parameters given. |
void |
setSalt(byte[] newSalt,
int offset,
int saltLen)
Sets the salt value for PBE algorithms. |
unwrapPrivateKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean pkcs8)
This method decrypts |
|
abstract JSAFE_PrivateKey |
unwrapPrivateKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean pkcs8,
String unwrappedKeyDevice)
This method decrypts |
unwrapPublicKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean ber)
This method decrypts |
|
abstract JSAFE_PublicKey |
unwrapPublicKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean ber,
String unwrappedKeyDevice)
This method decrypts |
unwrapSecretKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean ber,
String encryptedKeyAlgorithm)
This method decrypts |
|
abstract JSAFE_SecretKey |
unwrapSecretKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean ber,
String encryptedKeyAlgorithm,
String unwrappedKeyDevice)
This method decrypts |
byte[] |
wrapPrivateKey(JSAFE_PrivateKey keyToWrap,
boolean pkcs8)
Encrypt the private key's data. |
byte[] |
wrapPrivateKey(JSAFE_PrivateKey keyToWrap,
boolean pkcs8,
String format)
Encrypt the private key's data. |
byte[] |
wrapPublicKey(JSAFE_PublicKey keyToWrap,
boolean ber)
This method encrypts |
byte[] |
wrapSecretKey(JSAFE_SecretKey keyToWrap,
boolean ber)
Encrypts |
| Methods inherited from class com.rsa.jsafe.JSAFE_Object |
clone, overwrite, overwrite |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public JSAFE_SymmetricCipher()
| Method Detail |
public static JSAFE_SymmetricCipher getInstance(byte[] berAlgID,
int offset,
String device)
throws JSAFE_UnimplementedException,
JSAFE_InvalidParameterException,
JSAFE_IVException
berAlgID, beginning
at offset. This is the BER encoding of the algorithm
identifier. The specified device is used.
The value encoded in berAlgID must follow the definition
in X.509:
AlgorithmIdentifier ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameters ANY DEFINED BY algorithm OPTIONAL }
berAlgID - A byte array containing the BER encoding
of an algorithm ID.offset - The offset into berAlgID where
the encoding begins.device - A list of devices used to build the object.
JSAFE_SymmetricCipher object that performs the
transformation as described by the algorithm ID.
JSAFE_UnimplementedException - If the device or devices cannot
perform the designated algorithm, or the toolkit cannot decode the
BER encoding.
JSAFE_InvalidParameterException - If the BER encoding
contains parameters that do not work.
JSAFE_IVException - If the transformation needs an
initialization vector (iv), but the BER encoding did not contain one.
public static int getNextBEROffset(byte[] berAlgID,
int offset)
throws JSAFE_UnimplementedException
berAlgID, the BER encoding of the algorithm ID,
beginning at offset, returns the index to the next
byte in the array.
berAlgID - A byte array containing the BER encoding
of an algorithm ID.offset - The offset into berAlgID where the encoding
begins.
berAlgID of the byte following the
algorithm ID.
JSAFE_UnimplementedException - If the toolkit cannot decode the
BER encoding.
public static JSAFE_SymmetricCipher getInstance(String transformation,
String device)
throws JSAFE_UnimplementedException,
JSAFE_InvalidParameterException
transformation on the
given device. The transformation values are:
The algorithm value must be one of the following:
| algorithm values | Description |
| RC2-e | Where e is effective key bits, and is an integer from 1 to 1024. |
| RC5-v-w-r | Where v is the version number (currently, only 0x10 is supported), w is the word size in bits (an integer that is either 32 or 64), and r is the rounds (an integer from 0 to 255). |
| DES, 3DES_EDE | Data Encryption Standard and Triple-DES EDE. |
| DESX | DESX is an extension to DES. DESX is proprietary to RSA Security. |
| RC4 | RC4 Stream Cipher. |
| AES | General AES, implementation based on actual key size |
| AES128 | AES with 128-bit key, can be initialized only with 128-bit AES key |
| AES192 | AES with 192-bit key, can be initialized only with 192-bit AES key |
| AES256 | AES with 256-bit key, can be initialized only with 256-bit AES key |
Feedback Mode and Padding Schemes
The RC2 and RC5 ciphers, DES, and 3DES_EDE (Triple-DES EDE) are block ciphers that require a feedback mode and a padding scheme. The RC4 cipher is a stream cipher that does not let you specify feedback or padding. Possible feedback values are as follows:
| Feedback Values | Description |
| ECB | Electronic Codebook |
| CBC | Cipher Block Chaining |
| CFB-b | Cipher Feedback |
| OFB-b | Output Feedback |
where b is the block size. It must be a multiple of eight and cannot be larger than the underlying encryption block size. If no block size is given, the default is the cipher's block size.
The Crypto-J nomenclature differs from nomenclature used in the documentation of the standard, as shown in the following table:
| Algorithm | Crypto-J Name | Standard Name |
| AES | CFB | CFB128 | CFB-128 | CFB128 | CFB-8 | CFB8 | OFB | OFB128 | OFB-128 | OFB128 | OFB-8 | OFB8 |
| DES/TDES | CFB | CFB64 | CFB-64 | CFB64 | CFB-8 | CFB8 | OFB | OFB64 | OFB-64 | OFB64 | OFB-8 | OFB8 |
Possible padding schemes are as follows:
| Padding Schemes | Description |
| "NoPad" | Do not use padding |
| "PKCS5Padding" | Use PKCS #5 padding |
| "ISO10126Padding" | Use ISO 10126 padding |
Possible digest values are as follows:
Note: Cryptanalytic work has discovered a collision in MD2's internal compression
function, and there is a chance that the attack on MD2 may be extended to the
full hash function. RSA Security recommends not using MD2 except for
backward compatibility.
Another attack has been applied to the compression function on MD5, though
this has yet to be extended to the full MD5. RSA Security recommends that
before you use MD2 or MD5, you should consult the RSA Laboratories Web
site at http://www.rsasecurity.com/rsalabs/ to be sure that their use is
consistent with the latest information. One bulletin that discusses this issue is
Recent Results for MD2, MD4, and MD5; it is available at http://
www.rsasecurity.com/rsalabs/bulletins/.
The value of PBEStandard must be one of the following. Refer to PBEConverter.pdf for the correct
usage of PBE.
RSA Security recommends using an iteration count of 1000 (one thousand). There is no real limit to this value: the number must be positive and the bigger the number, the slower the operation. Following is a list of valid key size values allowed by the encryption algorithms.
Note that PKCS #5 PBE specifies the number of bits for DES or the RC2 cipher at 64. See the Crypto-J Developer's Guide ("Overview of Cryptography") for more information on Password-Based Encryption.
The
Note: Do not attempt to use hardware versions of Crypto-J classes unless you are
very familiar with the hardware. Refer to the "Cryptographic Hardware" section
in the Crypto-J Developer's Guide , which describes hardware usage,
its benefits, and its problems.
Examples:
The following example demonstrates how to use DES in ECB mode with padding and a hardware accelerator, as shown below. Crypto-J tries to do it first using the fictional company Acme's hardware accelerator. If the Acme device is not attached (or is attached but cannot perform DES), Crypto-J tries to build an object that performs DES using native code. If a native version is not available, Crypto-J uses the Java version.
JSAFE_SymmetricCipher des = JSAFE_SymmetricCipher.getInstance
("DES/ECB/NoPad", "Acme/Native/Java");
The following example demonstrates how to use the RC4 cipher with Native code, as
shown below. If a native version is not available, Crypto-J throws an exception.
JSAFE_SymmetricCipher rc4 =
JSAFE_SymmetricCipher.getInstance (“RC4”, “Native”);
The following example demonstrates how to use PKCS #12 PBE with SHA1 and the
RC2 cipher in CBC mode.
JSAFE_SymmetricCipher rc2PBE = JSAFE_SymmetricCipher.getInstance
("PBE/SHA1/RC2/CBC/PKCS12PBE–5–128", "Java");
transformation - The representation of the desired operation
(for example, "RC2-128/CBC/PKCS5Padding").device - A list of devices to use when building the object
(for example, "Java", "Native/Java").
JSAFE_SymmetricCipher object that performs the
transformation.
JSAFE_UnimplementedException - If the device or devices cannot
perform the designated algorithm.
JSAFE_InvalidParameterException - If the
transformation contains parameters that do not work.
public abstract byte[] getDERAlgorithmID()
throws JSAFE_UnimplementedException
byte array containing the DER encoding
of the algorithm ID of the algorithm in this object.
The PBE salt must be set before calling getDERAlgorithmID().
byte array that contains the algorithm ID.
JSAFE_UnimplementedException - If the algorithm has no OID,
or there is not enough information to build the algorithm ID.public String getDevice()
public String[] getDeviceList()
String array that describes all the
devices used to execute the transformation. Because
a transformation often consists of component algorithms,
the implementation can consist of several component
Objects. A device can perform one or more of the algorithms,
but it may let Java or another device perform one or more. For
example, because padding is not time-consuming, a device might
let the Crypto-J implementation perform padding. Returns the
names of the devices used by each component.
String array that describes the device used for a
specific component.public abstract String getEncryptionAlgorithm()
String array that describes the encryption algorithm.public String getFeedbackMode()
null.
String that describes the feedback mode.public String getPaddingScheme()
null.
String that describes the padding algorithm.public String getDigestAlgorithm()
null.
String that describes the digest algorithm.public String getPasswordStandard()
null.
String that describes the PBE standard.public int getBlockSize()
int that is the block size.public JSAFE_SecretKey getBlankKey()
JSAFE_SecretKey object to match the
algorithm and device of this object.
Key data can be set or generated with this object.
JSAFE_SecretKey object.public abstract int[] getAlgorithmParameters()
int array containing the algorithm's parameters.
For example, if the underlying algorithm is the RC2 algorithm, the return
value is an array of length 1, with the only element being
effective key bits. If the algorithm is the RC5 algorithm, the return value
is an array of length 3: version, word size in bits,
and rounds. If the underlying algorithm does not have parameters,
the return value is a zero-element array.
This may be an array of length 0.
int array containing the parameters.
public abstract void setAlgorithmParameters(int[] params)
throws JSAFE_InvalidParameterException
params - The algorithm parameters.
JSAFE_InvalidParameterException - If the parameters given
do not match the encryption algorithm.public int[] getFeedbackParameters()
int array containing the feedback mode's
parameters.
This may be an array of length 0.
int array that contains the parameters.public int[] getPaddingParameters()
int array containing the padding scheme's
parameters.
This may be an array of length 0.
int array that contains the parameters of
the padding scheme.public int[] getPBEParameters()
int array containing the PBE parameters, which
are generally the iteration count and key size.
int array that contains the PBE parameters.
public void setPBEParameters(int[] params)
throws JSAFE_InvalidParameterException
params - The PBE parameters. This is at most a two element
int array.
The first element is the iteration count. The second element
is the key size and is optional.
JSAFE_InvalidParameterException - If the parameters given
do not match the encryption algorithm.
public void generateIV(SecureRandom random)
throws JSAFE_IVException,
JSAFE_InvalidUseException
random.
This IV is stored internally and used after the next call to an
Init method.
The class JSAFE_SecureRandom is a subclass of
java.security.SecureRandom, so an object of that class is
valid input for random.
Call getIV() to see the IV that is generated.
This method does not save the random object. It does not use a random object
passed in during a previous call to generateIV(),
generateSalt(), or Init.
If null is passed in, this method throws an exception.
random - A SecureRandom object random bytes are drawn
from.
JSAFE_IVException - If the feedback mode rejects the IV.
JSAFE_InvalidUseException - If no random object is passed in.getIV(),
setIV(byte[], int, int)
public void setIV(byte[] iv,
int offset,
int ivLen)
throws JSAFE_IVException
ivLen bytes of
iv, beginning at offset. If an object already
possesses an IV, this method replaces it. However, the new IV does not
take effect until after the next Init, ReInit,
or Final call. This means that this new IV is not used if
the next method call is an Update.
The new IV must be the same length as the block size, or this method throws an exception. This method is meaningful only with block ciphers using a feedback mode (not ECB).
iv - The byte array containing the data.offset - The offset into iv where the data begins.ivLen - The length of the IV.
JSAFE_IVException - If the IV given is not the appropriate length.generateIV(java.security.SecureRandom),
getIV()public byte[] getIV()
byte array.
If the underlying algorithm does not use an IV (such as the RC4 cipher),
or if the IV has not yet been set, this method returns null.
byte array containing the IV.generateIV(java.security.SecureRandom),
setIV(byte[], int, int)
public void generateSalt(SecureRandom random)
throws JSAFE_InvalidUseException
random. The class
JSAFE_SecureRandom object is a subclass of
java.security.SecureRandom, so an object of that class is
valid input for random.
getSalt() can be called to retrieve the salt that is
generated. This salt is stored internally and used after the next call
to an Init method.
This method will not save the random object.
It will also not use a random object passed in during a
previous call to generateIV(), generateSalt(),
or Init. If random is null, this
method throws an exception.
random - A SecureRandom object random bytes are
drawn from.
JSAFE_InvalidUseException - If no random object
is passed in.getSalt(),
setSalt(byte[], int, int)
public void setSalt(byte[] newSalt,
int offset,
int saltLen)
Init, ReInit,
or Final call.
This means that this new salt is not used if the next method call is an
Update. This method is meaningful only when employing PBE.
newSalt - The byte array containing the data.offset - The offset into newSalt where the data begins.saltLen - The length of the salt.getSalt(),
generateSalt(java.security.SecureRandom)public byte[] getSalt()
byte array. If an object is not performing PBE,
or if the salt has not been set yet, this method returns null.
byte array containing the salt.setSalt(byte[], int, int),
generateSalt(java.security.SecureRandom)public abstract int getOutputBufferSize(int inputLen)
Update and Final) given the length of the input
inputLen. The computation includes the length of
any unprocessed data.
However, the actual output may be smaller than the reported value.
inputLen - The length of the input, in bytes.
int that indicates the size of the output.
public void encryptInit(JSAFE_SecretKey key)
throws JSAFE_InvalidUseException,
JSAFE_InvalidKeyException,
JSAFE_IVException
key,
which must be instantiated with the same algorithm.
If the encryption algorithm, feedback, or padding scheme require random
bytes, this method throws an exception.
(Currently, no symmetric encryption algorithm feedback
or symmetric padding scheme supported by Crypto-J requires random bytes.
However, if a future version contains an algorithm that needs a random
object, encryptInit() throws an exception when trying to call
Init.)
key - A JSAFE_SecretKey that is used to encrypt.
JSAFE_InvalidUseException - If the object cannot be
initialized.
JSAFE_InvalidKeyException - If the key object does not match
this object (for example, if it is a different algorithm or
different device).
JSAFE_IVException - If the algorithm needs an IV,
and the one entered is inappropriate.
public abstract void encryptInit(JSAFE_SecretKey key,
SecureRandom random)
throws JSAFE_InvalidUseException,
JSAFE_InvalidKeyException,
JSAFE_IVException
key and
random. If this object ever needs random bytes,
encryptInit() uses random.
If an algorithm does not need random bytes, random can have a
null value or use the encryptInit() method that
does not take a random object.
The JSAFE_SecureRandom is a subclass of
java.security.SecureRandom, so an object of that
class is valid input for random.
key - A JSAFE_SecretKey object that will be used to
encrypt.random - A SecureRandom from which this object draws
random bytes if necessary.
JSAFE_InvalidUseException - If the object cannot be initialized.
JSAFE_InvalidKeyException - If the key object does not match
this object (for example, if it is a different algorithm or a
different device).
JSAFE_IVException - If the algorithm needs an IV
and the one entered is inappropriate.
public abstract void encryptReInit()
throws JSAFE_InvalidUseException,
JSAFE_IVException
encryptInit() method.
This method cannot be called when the RC4 cipher is used.
JSAFE_InvalidUseException - If the object is not initialized
for encryption.
JSAFE_IVException - If the algorithm needs an initialization
vector (IV), and the one entered is inappropriate.
public byte[] encryptUpdate(byte[] partIn,
int offset,
int partInLen)
throws JSAFE_InvalidUseException,
JSAFE_IVException
partInLen bytes of the array
partIn, beginning at offset.
It returns the result in a new byte array.
The result may be a zero-length array.
If there is not enough data to form a block, encryptUpdate()
will not encrypt.
In that case, it stores the input in an internal buffer.
partIn - The data to encrypt.offset - The offset into partIn where the data begins.partInLen - The length of the data to encrypt.
byte array containing the encrypted data.
This may be an array of length 0 if the object could not
encrypt yet.
JSAFE_InvalidUseException - If the object is not initialized
to encrypt.
JSAFE_IVException - If the object needs an initialization vector
(IV), and does not have one.
public abstract int encryptUpdate(byte[] partIn,
int inOffset,
int partInLen,
byte[] partOut,
int outOffset)
throws JSAFE_InvalidUseException,
JSAFE_IVException
partInLen bytes of the array
partIn, beginning at inOffset.
It returns the result in the byte array partOut,
beginning at outOffset. The return value is the number of
bytes placed in the output buffer.
This method does not encrypt if there is not enough data to form a block. In that case, it stores the input in an internal buffer.
partIn - The data to encrypt.inOffset - The offset into partIn where the data begins.partInLen - The length of the data to encrypt.partOut - The buffer where the output is placed.outOffset - The offset into partOut where the writing
begins.
JSAFE_InvalidUseException - If the object is not initialized
to encrypt.
JSAFE_IVException - If the object needs an initialization vector
(IV), and does not have one.
public byte[] wrapPrivateKey(JSAFE_PrivateKey keyToWrap,
boolean pkcs8)
throws JSAFE_InvalidUseException
true for the argument
pkcs8. This method encrypts keyToWrap.
The encrypted key is the BER encoding of the private key
(PrivateKeyInfo, as defined in PKCS #8).
encryptInit() or encryptReInit() must be called
prior to calling this method.
If the argument pkcs8 is false, the result is
the key data encrypted.
If the argument pkcs8 is true, the result is
returned in the PKCS #8 EncryptedPrivateKeyInfo
standard definition format, as defined below:
EncryptedPrivateKeyInfo ::= SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier,
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
EncryptedData ::= OCTET STRING
keyToWrap - The object containing the key to encrypt.pkcs8 - Pass in true to get a result that is
BER encoded following PKCS #8, false to get only
the encrypted data.
JSAFE_InvalidUseException - If the object has not been
initialized to encrypt.
public byte[] wrapPrivateKey(JSAFE_PrivateKey keyToWrap,
boolean pkcs8,
String format)
throws JSAFE_InvalidUseException
true for the argument
pkcs8. This method encrypts keyToWrap.
The encrypted key is the BER encoding of the private key
(PrivateKeyInfo, as defined in PKCS #8).
encryptInit or encryptReInit must be called prior
to calling this method.
If the argument pkcs8 is false, the result is
the key data encrypted. If the argument pkcs8 is
true, the result is returned in the PKCS #8
EncryptedPrivateKeyInfo standard definition format,
as defined below:
EncryptedPrivateKeyInfo ::= SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier,
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
EncryptedData ::= OCTET STRING
keyToWrap - The object containing the key to encrypt.pkcs8 - true to get a result that is BER encoded
following PKCS #8, false to get only the encrypted data.format - The key data format.
JSAFE_InvalidUseException - If the object has not been
initialized to encrypt.
public byte[] wrapPublicKey(JSAFE_PublicKey keyToWrap,
boolean ber)
throws JSAFE_InvalidUseException
keyToWrap. The encrypted key is the
BER encoding of the public key (SubjectPublicKeyInfo,
as defined in X.509).
encryptInit() or encryptReInit() must be called
prior to calling this method.
If the argument ber is false,
the result is the key data encrypted.
If the argument ber is true,
the result is returned as a BER-encoded encryptedPublicKey
(proprietary to RSA Security) as defined below:
EncryptedPublicKey ::=SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier,
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
EncryptedData ::= OCTET STRING
keyToWrap - The object containing the key to encrypt.ber - true to get a result that is BER encoded,
false to get only the encrypted data.
byte array containing the encrypted key.
JSAFE_InvalidUseException - If the object is not
initialized to encrypt.
public byte[] wrapSecretKey(JSAFE_SecretKey keyToWrap,
boolean ber)
throws JSAFE_InvalidUseException
keyToWrap. Call encryptInit() or
encryptReInit() before calling this method.
If the argument ber is false,
the result is the key data encrypted.
If the argument ber is true,
the result is the BER encoding of the secret key
SecretKeyInfo (proprietary to RSA Security) as defined below:
SecretKeyInfo ::=SEQUENCE {
secretKeyAlgorithm AlgorithmIdentifier
secretKey OCTET STRING }
EncryptedSecretKey ::=SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::=AlgorithmIdentifier
EncryptedData ::= OCTET STRING
keyToWrap - The object containing the key to encrypt.ber - true to get a result that is BER encoded,
false to get only the encrypted data.
byte array containing the encrypted key.
JSAFE_InvalidUseException - If the object is not
initialized to encrypt.
public byte[] encryptFinal()
throws JSAFE_InvalidUseException,
JSAFE_InputException,
JSAFE_IVException,
JSAFE_PaddingException
byte array.
Call a Final method before reusing the object to
encrypt with a new key.
JSAFE_InvalidUseException - If the object has not been
initialized to encrypt.
JSAFE_InputException - If the input is not an appropriate
length (for example, an unpadded block cipher with input that is not
a multiple of the block size).
JSAFE_IVException - If the algorithm needs an initialization
vector (IV) and does not have one.
JSAFE_PaddingException - If the padding algorithm cannot execute.
public abstract int encryptFinal(byte[] partOut,
int offset)
throws JSAFE_InvalidUseException,
JSAFE_InputException,
JSAFE_IVException,
JSAFE_PaddingException
partOut,
beginning at offset. The return value is the
number of bytes actually placed in the output buffer.
A Final method must be called before reusing the object
to encrypt with a new key.
The return value is the number of bytes actually placed in the
output buffer.
partOut - The buffer where the output is placed.offset - The offset into partOut where the writing
begins.
JSAFE_InvalidUseException - If the object is not
initialized to encrypt.
JSAFE_InputException - If the input is not an appropriate
length (for example, an unpadded block cipher with input that is not a
multiple of the block size).
JSAFE_IVException - If the algorithm needs an IV,
and does not have one.
JSAFE_PaddingException - If the padding algorithm cannot execute.
public void decryptInit(JSAFE_SecretKey key)
throws JSAFE_InvalidUseException,
JSAFE_InvalidKeyException,
JSAFE_IVException
key, which must
be instantiated with the same algorithm. If the decryption algorithm,
feedback, or padding require random bytes, this method throws an
exception. (Currently, neither symmetric decryption algorithm feedback nor
symmetric padding schemes supported by Crypto-J require random bytes.
However, if a future version contains an algorithm that needs a random
object, decryptInit() throws an exception when trying to call
Init.)
key - A JSAFE_SecretKey object that is used to decrypt.
JSAFE_InvalidUseException - If the object cannot be
initialized.
JSAFE_InvalidKeyException - If the key object does not match
this object (for example, if it is a different algorithm or different
device).
JSAFE_IVException - If the algorithm needs an
IV, and the one entered is inappropriate.
public abstract void decryptInit(JSAFE_SecretKey key,
SecureRandom random)
throws JSAFE_InvalidUseException,
JSAFE_InvalidKeyException,
JSAFE_IVException
key, which must have been instantiated with the same
algorithm. If the decryption algorithm, feedback, or padding scheme
needs to obtain random bytes, an object gets them from random.
If an algorithm does not need random bytes, either pass in a
null value or use the decryptInit()
method that does not take a random object.
key - A JSAFE_SecretKey object that is used to decrypt.random - A SecureRandom where random bytes are drawn from,
if necessary. The JSAFE_SecureRandom object is a subclass of
the SecureRandom object, so it is valid input.
JSAFE_InvalidUseException - If the object cannot be initialized.
JSAFE_InvalidKeyException - If the key object does not match
this object (for example, if it is a different algorithm or a
different device).
JSAFE_IVException - If the algorithm needs an IV, and the
one entered is inappropriate.
public abstract void decryptReInit()
throws JSAFE_InvalidUseException,
JSAFE_IVException
decryptInit().
This method cannot be called when RC4 is being used.
JSAFE_InvalidUseException - If the object is not initialized
for decryption.
JSAFE_IVException - If the algorithm needs an IV,
and the one entered is inappropriate.
public JSAFE_PrivateKey unwrapPrivateKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean pkcs8)
throws JSAFE_InvalidUseException
wrappedKey
(of length keyLen, beginning at offset) and
returns the result as a new JSAFE_PrivateKey.
If the argument pkcs8 is false,
pass in the encrypted key data. If the argument pkcs8
is true, this method expects the data to be in the form
of PKCS #8 EncryptedPrivateKeyInfo standard definition format,
as defined below:
EncryptedPrivateKeyInfo ::= SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier,
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
EncryptedData ::= OCTET STRING
Call decryptInit() or decryptReInit() before
calling this method.
wrappedKey - The encrypted key data.offset - The offset into wrappedKey where the data
begins.keyLen - The length of the encrypted data.pkcs8 - true if the key is encrypted following
PKCS #8, false otherwise.
JSAFE_PrivateKey object built using the
decrypted data.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
public abstract JSAFE_PrivateKey unwrapPrivateKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean pkcs8,
String unwrappedKeyDevice)
throws JSAFE_InvalidUseException
wrappedKey
(of length keyLen, beginning at offset) and
returns the result as a new JSAFE_PrivateKey object,
the device of the resulting key described by
unwrappedKeyDevice.
If the argument pkcs8 is false,
pass in the encrypted key data.
If the argument pkcs8 is true,
this method expects the data to be in the form of PKCS #8
EncryptedPrivateKeyInfo standard definition format,
as defined below:
EncryptedPrivateKeyInfo ::= SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier,
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
EncryptedData ::= OCTET STRING
Call decryptInit() or decryptReInit() before
calling this method.
wrappedKey - The encrypted key data.offset - The offset into wrappedKey where the data
begins.keyLen - The length of the encrypted data.pkcs8 - true if the key is encrypted following
PKCS #8, false otherwise.unwrappedKeyDevice - Specifies the device for the resulting
private key.
JSAFE_PrivateKey object built using the
decrypted data.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
public JSAFE_PublicKey unwrapPublicKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean ber)
throws JSAFE_InvalidUseException
wrappedKey
(of length keyLen, beginning at offset) and
returns the result as a new JSAFE_PublicKey.
If the argument ber is false,
pass in the encrypted key data.
If the argument ber is true,
this method expects the data to be in the form of an
EncryptedPublicKey(proprietary to RSA Security)
as defined below:
EncryptedPublicKey ::=SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier,
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
EncryptedData ::= OCTET STRING
Call decryptInit() or decryptReInit() before
calling this method.
wrappedKey - The encrypted key data.offset - The offset into wrappedKey where the data
begins.keyLen - The length of the encrypted data.ber - true if the key is encrypted BER encoded,
false otherwise.
JSAFE_PublicKey object built using the
decrypted data.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
public abstract JSAFE_PublicKey unwrapPublicKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean ber,
String unwrappedKeyDevice)
throws JSAFE_InvalidUseException
wrappedKey
(of length keyLen, beginning at offset) and
returns the result as a new JSAFE_PublicKey object where
the device of the resulting key is described by
unwrappedKeyDevice.
If the argument ber is false,
pass in the encrypted key data.
If the argument ber is true,
this method expects the data to be in the form of an
EncryptedPublicKey (proprietary to RSA Security)
as defined below:
EncryptedPublicKey ::=SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier,
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
EncryptedData ::= OCTET STRING
Call decryptInit() or decryptReInit() before
calling this method.
wrappedKey - The encrypted key data.offset - The offset into wrappedKey where the data
begins.keyLen - The length of the encrypted data.ber - true if the key is encrypted BER encoded,
false otherwise.unwrappedKeyDevice - Specifies the device for the resulting
public key.
JSAFE_PublicKey object built using the
decrypted data.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
public JSAFE_SecretKey unwrapSecretKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean ber,
String encryptedKeyAlgorithm)
throws JSAFE_InvalidUseException
wrappedKey
(of length keyLen, beginning at offset) and
returns the result as a new JSAFE_SecretKey.
If the argument ber is false,
pass in the encrypted key's algorithm in
encryptedKeyAlgorithm.
If the argument ber is true,
this method expects the data to be in the form of an
EncryptedSecretKey (proprietary to RSA Security)
as defined below, and the method ignores the argument
encryptedKeyAlgorithm:
SecretKeyInfo ::=SEQUENCE {
secretKeyAlgorithm AlgorithmIdentifier
secretKey OCTET STRING }
EncryptedSecretKey ::=SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::=AlgorithmIdentifier
EncryptedData ::= OCTET STRING
Call decryptInit() or decryptReInit() before
calling this method.
wrappedKey - The encrypted key data.offset - The offset into wrappedKey where the data
begins.keyLen - The length of the encrypted data.ber - true if the key is encrypted BER encoded,
false otherwise.encryptedKeyAlgorithm - If ber is false,
use this parameter to specify which algorithm the key is for
(for example, "DES", "RC4").
JSAFE_SecretKey object built using the
decrypted data.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
public abstract JSAFE_SecretKey unwrapSecretKey(byte[] wrappedKey,
int offset,
int keyLen,
boolean ber,
String encryptedKeyAlgorithm,
String unwrappedKeyDevice)
throws JSAFE_InvalidUseException
wrappedKey
(of length keyLen, beginning at offset) and
returns the result as a new JSAFE_SecretKey object where
the device of the resulting key is described by
unwrappedKeyDevice.
If the argument
ber is false,
pass in the encrypted key's algorithm in
encryptedKeyAlgorithm.
If the argument for ber is true,
this method expects the data to be in the form of an
EncryptedSecretKey (proprietary to RSA Security)
as defined below, and the method ignores the argument
encryptedKeyAlgorithm:
SecretKeyInfo ::=SEQUENCE {
secretKeyAlgorithm AlgorithmIdentifier
secretKey OCTET STRING }
EncryptedSecretKey ::=SEQUENCE {
encryptionAlgorithm EncryptionAlgorithmIdentifier
encryptedData EncryptedData }
EncryptionAlgorithmIdentifier ::=AlgorithmIdentifier
EncryptedData ::= OCTET STRING
Call decryptInit() or decryptReInit() before
calling this method.
wrappedKey - The encrypted key data.offset - The offset into wrappedKey where the data
begins.keyLen - The length of the encrypted data.ber - true if the key was encrypted BER encoded,
false otherwise.encryptedKeyAlgorithm - If ber is false,
use this parameter to specify which algorithm the key is for
(for example, "DES", "RC4").unwrappedKeyDevice - Specifies the device for the resulting
secret key.
JSAFE_SecretKey object built using the
decrypted data.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
public byte[] decryptUpdate(byte[] partIn,
int offset,
int partInLen)
throws JSAFE_InvalidUseException,
JSAFE_IVException
partInLen bytes of the array
partIn, beginning at offset.
Returns the result in a new byte array.
The result may be a zero-length array.
It will not decrypt if there is not enough data to form a block.
In that case, it stores the input in an internal buffer.
partIn - The data to decrypt.offset - The offset into partIn where the data begins.partInLen - The length of the data to decrypt.
byte array containing the decrypted data.
This may be an array of length 0 if the object could not
decrypt yet.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
JSAFE_IVException - If the object needs an IV,
and does not have one.
public abstract int decryptUpdate(byte[] partIn,
int inOffset,
int partInLen,
byte[] partOut,
int outOffset)
throws JSAFE_InvalidUseException,
JSAFE_IVException
partInLen bytes of the array
partIn, beginning at inOffset.
It places the result in the byte array
partOut, beginning at outOffset.
The return value is the number of bytes placed in the output buffer.
It will not decrypt if there is not enough data to form a block.
In that case, it stores the input in an internal buffer.
partIn - The data to decrypt.inOffset - The offset into partIn where the data begins.partInLen - The length of the data to decrypt.partOut - The buffer where the output is placed.outOffset - The offset into partOut where the writing
begins.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
JSAFE_IVException - If the object needs an initialization
vector (IV), and does not have one.
public byte[] decryptFinal()
throws JSAFE_InvalidUseException,
JSAFE_InputException,
JSAFE_IVException,
JSAFE_PaddingException
byte array.
If there are no output bytes, returns a zero-length array.
Call a Final method before reusing the object to decrypt
with a new key.
byte array containing the decrypted data.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
JSAFE_InputException - If the input is not an appropriate length.
JSAFE_IVException - If the algorithm needs an initialization
vector (IV) and does not have one.
JSAFE_PaddingException - If the padding algorithm cannot execute.
public abstract int decryptFinal(byte[] partOut,
int offset)
throws JSAFE_InvalidUseException,
JSAFE_InputException,
JSAFE_IVException,
JSAFE_PaddingException
partOut,
beginning at offset. The return value is the number of bytes
that are actually placed in the output buffer. Call a Final
method before reusing the object to decrypt with a new key.
partOut - The buffer where the output is placed.offset - The offset into partOut where the writing
begins.
JSAFE_InvalidUseException - If the object is not initialized
to decrypt.
JSAFE_InputException - If the input is not an appropriate length.
JSAFE_IVException - If the algorithm needs an initialization
vector (IV) and does not have one.
JSAFE_PaddingException - If the padding algorithm cannot execute.public void clearSensitiveData()
clearSensitiveData(),
an Init (not a ReInit) method is
called to perform other operations with the object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||