|
||||||||||
| 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_MAC
The JSAFE_MAC class provides a framework for MACs.
Crypto-J implements HMAC, as defined in RFC 2104 and RFC 2202.
This class instantiates the classes that create and verify
MACs, and defines the functionality.
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_MAC()
|
|
| Method Summary | |
void |
clearSensitiveData()
This method clears sensitive data from an object. |
void |
generateSalt(SecureRandom saltRandom)
Provides a common interface used as a convenience for the password-based MAC. |
abstract int[] |
getAlgorithmParameters()
Returns a new |
getBlankKey()
Returns an empty |
|
abstract byte[] |
getDERAlgorithmID()
Returns a new |
getDevice()
Returns the name of the device of record. |
|
String[] |
getDeviceList()
Returns a |
abstract String |
getDigestAlgorithm()
Returns the standard digest algorithm name. |
static JSAFE_MAC |
getInstance(byte[] berAlgID,
int offset,
String device)
Builds an object based on the algorithm ID. |
static JSAFE_MAC |
getInstance(String transformation,
String device)
Builds a |
abstract String |
getMACAlgorithm()
Returns the standard MAC algorithm name. |
abstract int |
getMACSize()
Returns the size (in bytes) of the MAC output, or |
static int |
getNextBEROffset(byte[] berAlgID,
int offset)
Given the |
byte[] |
getSalt()
Returns the salt that was either set or generated using a PRNG. |
byte[] |
macFinal()
Finalizes the calculation of the MAC and returns the result in
a new |
abstract int |
macFinal(byte[] output,
int offset)
Finalizes the message authentication process. |
abstract void |
macInit(JSAFE_SecretKey secretKey,
SecureRandom random)
Initializes the MAC object to perform message authentication
using the supplied |
abstract void |
macReInit()
Re-initializes this object to calculate the MAC, using the key passed in
during an earlier call to |
abstract void |
macUpdate(byte[] partIn,
int offset,
int partInLen)
Updates the message authentication process with the first
|
void |
setSalt(byte[] newSalt,
int offset,
int saltLen)
Sets the salt value for PBE algorithms. |
abstract boolean |
verifyFinal(byte[] mac,
int offset,
int macLen)
Determines whether or not the MAC verifies an object by comparing it with a reference MAC. |
abstract void |
verifyInit(JSAFE_SecretKey secretKey,
SecureRandom random)
Initializes this object to verify using the specified secret key and random objects. |
abstract void |
verifyReInit()
Re-initializes this object to verify a MAC using the key passed in during
a previous call to |
abstract void |
verifyUpdate(byte[] partIn,
int offset,
int partInLen)
Updates the message verification by processing the first
|
| 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_MAC()
| Method Detail |
public static JSAFE_MAC getInstance(byte[] berAlgID,
int offset,
String device)
throws JSAFE_UnimplementedException,
JSAFE_InvalidParameterException
berAlgID - A byte array containing the BER encoding
of an algorithm ID.offset - The offset into berAlgID where the BER encoding
begins.device - A list of devices used to build the object.
JSAFE_MAC 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.
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. In other words, gets the next offset after
the algorithm ID.
berAlgID - A byte array containing the BER encoding of
an algorithm ID.offset - The offset into berAlgID where the BER encoding
begins.
berAlgID of the byte following the
algorithm ID.
JSAFE_UnimplementedException - If the toolkit cannot decode the
BER encoding.
public static JSAFE_MAC getInstance(String transformation,
String device)
throws JSAFE_UnimplementedException,
JSAFE_InvalidParameterException
JSAFE_MAC object that authenticates messages
according to the transformation, using the given
device.
The value of transformation must be one of the following:
transformation values
HMAC/MD5
HMAC/SHA1
HMAC/SHA224
HMAC/SHA256
HMAC/SHA384
HMAC/SHA512
PBE/HMAC/digest/PBEStandard
where the value of digest can be either MD5, SHA1, SHA224
, SHA256, SHA384 or SHA512 and
the value of the PBEStandard object can be either
PKCS12PBE-i-k (for backwards compatibility only) or
PKCS12V1PBE-i-k (recommended over PKCS12PBE-i-k),
where i is the iteration count and k refers to the key
size. 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. The key size (k) is a value from 0 to 2048.
The device value is as follows: "choice1{/choice2[...{/choicen]]]" where the choices are:
transformation - The representation of the desired operation
(for example, "HMAC/SHA1").device - A list of devices used to build the object
(for example, "Java", "Native/Java").
JSAFE_MAC 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.
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.
Returns the names of the devices used by each component.
String array that describes the device used for a
specific component.public abstract String getMACAlgorithm()
String that describes the MAC algorithm.public abstract String getDigestAlgorithm()
String that describes the digest algorithm.public abstract int[] getAlgorithmParameters()
int array containing the algorithm's parameters.
This may be an array of length 0.
int array that contains the parameters
of the algorithm.public abstract int getMACSize()
-1 if the
MAC is not initialized.
int that is the MAC output size.public JSAFE_SecretKey getBlankKey()
JSAFE_SecretKey object to match the
algorithm and device of this object.
Sets or generates the key data with this key object.
JSAFE_SecretKey object.
public abstract void macInit(JSAFE_SecretKey secretKey,
SecureRandom random)
throws JSAFE_InvalidUseException,
JSAFE_InvalidKeyException
secretKey and random objects.
If the algorithm does not require a SecureRandom object,
pass null. JSAFE_SecureRandom is a subclass of
java.security.SecureRandom, so an object of that class is
valid input for random.
Initializes this object to calculate the MAC using key.
secretKey - A JSAFE_SecretKey object used to calculate
the MAC.random - A SecureRandom object 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 different
device).
public abstract void macReInit()
throws JSAFE_InvalidUseException
macInit().
JSAFE_InvalidUseException - If the object is not initialized
to calculate the MAC.
public abstract void macUpdate(byte[] partIn,
int offset,
int partInLen)
throws JSAFE_InvalidUseException
partInLen bytes in the partIn array,
beginning at offset.
MACs the input data.
partIn - The data the MAC is calculated with.offset - The offset into partIn where the data begins.partInLen - The length of the data by which the MAC is calculated.
JSAFE_InvalidUseException - If the object is not
initialized to calculate the MAC.public byte[] getSalt()
null. This
is not needed in non-PBE HMAC.
byte array containing the salt.
public void setSalt(byte[] newSalt,
int offset,
int saltLen)
newSalt - The byte array containing the data.offset - The offset into newSalt where the data begins.saltLen - The length of the salt.
public void generateSalt(SecureRandom saltRandom)
throws JSAFE_InvalidUseException
saltRandom - A random number generator.
JSAFE_InvalidUseException - If no random object is passed in.
public byte[] macFinal()
throws JSAFE_InvalidUseException
byte array. Call a Final method before
reusing the object for authentication or verification.
byte array that contains the MAC result.
JSAFE_InvalidUseException - If the object is not
initialized to calculate the MAC.
public abstract int macFinal(byte[] output,
int offset)
throws JSAFE_InvalidUseException
byte array output,
beginning at offset. The return value is the number of
bytes actually placed in the output buffer.
Call a Final method before
reusing the object for authentication or verification.
output - The buffer where the output is placed.offset - The offset into output where the writing
begins.
JSAFE_InvalidUseException - If the object is not
initialized to calculate the MAC.
public abstract void verifyInit(JSAFE_SecretKey secretKey,
SecureRandom random)
throws JSAFE_InvalidUseException,
JSAFE_InvalidKeyException
SecureRandom object, pass null. The
JSAFE_SecureRandom object is a subclass of
java.security.SecureRandom, so an object of that class is
valid input for random.
An object that is initialized for verifying is not able to sign.
secretKey - A JSAFE_SecretKey object that is used to
verify the MAC.random - A SecureRandom object 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 different
device).
public abstract void verifyReInit()
throws JSAFE_InvalidUseException
verifyInit().
JSAFE_InvalidUseException - If the object is not initialized
to verify.
public abstract void verifyUpdate(byte[] partIn,
int offset,
int partInLen)
throws JSAFE_InvalidUseException
partInLen byte in the array partIn, beginning
at offset.
Continues MAC verification on the input data.
partIn - The data to be verified.offset - The offset into partIn where the data begins.partInLen - The length of the data to verify.
JSAFE_InvalidUseException - If the object is not
initialized to verify.
public abstract boolean verifyFinal(byte[] mac,
int offset,
int macLen)
throws JSAFE_InvalidUseException
mac,
beginning at offset and for macLen bytes.
Call a verifyFinal() or macFinal() method before
reusing the object for authentication or verification.
boolean. Returns true if the signature
verifies, false otherwise.
JSAFE_InvalidUseException - If the object is not
initialized to verify.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 | |||||||||