public class PasswordBasedMAC extends MessageDigest
HMAC-SHA1 and HMAC-MD5 for the underlying keyed MAC algorithm.PBMacAlgIDMessageDigest.MDState| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_ITER_COUNT
Default password-based key derivation iteration count.
|
static AlgorithmIdentifier |
DEFAULT_MAC
Default password-based MAC algorithm is HMAC-SHA.
|
static AlgorithmIdentifier |
DEFAULT_OWF
Default password-based key derivation hash function is SHA-1.
|
static int |
DEFAULT_SALT_LEN
Default password-based key derivation salt length.
|
algID| Constructor and Description |
|---|
PasswordBasedMAC()
Creates a new
PasswordBasedMAC instance. |
PasswordBasedMAC(AlgorithmIdentifier algID, byte[] password)
Creates a new
PasswordBasedMAC instance with the given algorithm identifier and password. |
PasswordBasedMAC(AlgorithmIdentifier algID, byte[] password, RandomBitsSource rbs)
Creates a new
PasswordBasedMAC instance with the given algorithm identifier and password. |
PasswordBasedMAC(byte[] password)
Creates a new
PasswordBasedMAC instance with the given password. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
algName()
Returns the algorithm name of this message digest.
|
int |
blockSize()
Returns the blocksize of this instance.
|
java.lang.Object |
clone()
Returns a clone of this message digest object.
|
void |
computeCurrent()
Completes the hash computation, performing any necessary operations such as padding.
|
AlgorithmIdentifier |
getAlgID()
Returns the algorithm identifier for this
PasswordBasedMAC. |
int |
getCount()
Returns the iteration count to use for password-based key derivation.
|
byte[] |
getDigestBits()
Returns a copy of the current digest bytes.
|
int |
getDigestLength()
Returns the length in bytes of the message digest.
|
AlgorithmIdentifier |
getMacAlgID()
Returns the keyed MAC algorithm to use.
|
AlgorithmIdentifier |
getOwfAlgID()
Returns the one-way (hash) function to use for password-based key derivation.
|
byte[] |
getSalt()
Gets the salt value used in this
PasswordBasedMAC. |
protected MessageDigest.MDState |
getState()
Gets the state of this MessageDigest instance.
|
void |
init()
Resets this message digest object to its initial state.
|
boolean |
isValid()
Returns
true if this PasswordBasedMAC is in a valid state and its digest bits are usable; otherwise returns false. |
void |
setAlgID(AlgorithmIdentifier algID)
Sets the algorithm identifier for this
PasswordBasedMAC. |
void |
setCount(int count)
Sets the iteration count to use for password-based key derivation.
|
void |
setMacAlgID(AlgorithmIdentifier macAlgID)
Sets the keyed MAC algorithm to use.
|
void |
setOwfAlgID(AlgorithmIdentifier owfAlgID)
Sets the one-way (hash) function to use for password-based key derivation.
|
void |
setPassword(byte[] password)
Sets the password to be used for this
PasswordBasedMAC. |
void |
setRandomBitsSource(RandomBitsSource rbs)
Sets the RNG to use for generating random salt bytes, if needed.
|
void |
setSalt(byte[] salt)
Sets the salt value.
|
protected void |
setState(MessageDigest.MDState state)
Sets the state of this MessageDigest instance.
|
void |
update(byte b)
Adds the specifed byte to the data being digested.
|
void |
update(byte[] input, int off, int len)
Adds the specified sequence of bytes to the data being digested.
|
computeDigest, computeDigest, getInstance, isEqual, toString, update, update, update, update, update, update, update, update, update, update, update, updateASCIIpublic static final int DEFAULT_SALT_LEN
PKCS5.DEFAULT_SALT_LEN, Constant Field Valuespublic static final AlgorithmIdentifier DEFAULT_OWF
public static final int DEFAULT_ITER_COUNT
PKCS5.DEFAULT_ITER_COUNT, Constant Field Valuespublic static final AlgorithmIdentifier DEFAULT_MAC
public PasswordBasedMAC()
PasswordBasedMAC instance.
public PasswordBasedMAC(byte[] password)
throws AlgorithmIdentifierException
PasswordBasedMAC instance with the given password. The default algorithm identifier AlgID.PasswordBasedMac will be used.password - The password to use.AlgorithmIdentiferException - If algID does not identify a password-based MAC or if an error occurs processing the parameters.AlgorithmIdentifierExceptionpublic PasswordBasedMAC(AlgorithmIdentifier algID, byte[] password) throws AlgorithmIdentifierException
PasswordBasedMAC instance with the given algorithm identifier and password.algID - The algorithm identifier to use.password - The password to use.AlgorithmIdentiferException - If algID does not identify a password-based MAC or if an error occurs processing the parameters.AlgorithmIdentifierExceptionPBMacAlgIDpublic PasswordBasedMAC(AlgorithmIdentifier algID, byte[] password, RandomBitsSource rbs) throws AlgorithmIdentifierException
PasswordBasedMAC instance with the given algorithm identifier and password. Use this constructor if algID does not contain parameters; the given RandomBitsSource will be used to generate the salt bytes.algID - The algorithm identifier to use.password - The password to use.rbs - The RNG to use for generating the salt bytes.AlgorithmIdentiferException - If algID does not identify a password-based MAC or if an error occurs processing the parameters.AlgorithmIdentifierExceptionPBMacAlgIDpublic void setAlgID(AlgorithmIdentifier algID) throws AlgorithmIdentifierException
PasswordBasedMAC.setAlgID in class MessageDigestalgID - The algorithm identifier to use.AlgorithmIdentiferException - If algID does not identify a password-based MAC or if an error occurs processing the parameters.AlgorithmIdentifierExceptionPBMacAlgIDpublic AlgorithmIdentifier getAlgID()
PasswordBasedMAC.
If all of the parameter fields (salt, one-way function algorithm, iteration count and MAC algorithm) are defined (or defaults can be used and/or generated), then a new PBMacAlgID containing the parameters is returned; otherwise a PBMacAlgID with no parameters is returned.
getAlgID in class MessageDigestjava.lang.IllegalStateException - If an error occurs constructing a new PBMacAlgID using the parameters present in this PasswordBasedMAC.PBMacAlgIDpublic void setSalt(byte[] salt)
salt - The salt value to use for password-based key derivation.PBMacAlgIDpublic byte[] getSalt()
PasswordBasedMAC.null is none is present.PBMacAlgIDpublic void setOwfAlgID(AlgorithmIdentifier owfAlgID) throws AlgorithmIdentifierException
owfAlgID - The algorithm identifier for the password-based key derivation one-way (hash) function.AlgorithmIdentifierExceptionPBMacAlgIDpublic AlgorithmIdentifier getOwfAlgID()
null if none is present.PBMacAlgIDpublic void setCount(int count)
count - The iteration count to use for password-based key derivation.PBMacAlgIDpublic int getCount()
PBMacAlgIDpublic void setMacAlgID(AlgorithmIdentifier macAlgID) throws AlgorithmIdentifierException
macAlgID - The algorithm identifier for the keyed MAC algorithm.AlgorithmIdentifierException - If macAlgID does not identify a a supported MAC algorithm.PBMacAlgIDpublic AlgorithmIdentifier getMacAlgID()
null if none is present.PBMacAlgIDpublic void setRandomBitsSource(RandomBitsSource rbs)
rbs - The RNG to use for generating random salt bytes.PBMacAlgIDpublic void setPassword(byte[] password)
PasswordBasedMAC.password - The bytes of the password.public void init()
MessageDigestinit in class MessageDigestpublic int blockSize()
MessageDigestblockSize in class MessageDigestpublic void update(byte b)
MessageDigestupdate in class MessageDigest
public void update(byte[] input,
int off,
int len)
MessageDigestupdate in class MessageDigestinput - the input arrayoff - start position in the input arraylen - the number of input array elements to add to the data being digestedpublic void computeCurrent()
MessageDigestMessageDigest.getDigestBits().computeCurrent in class MessageDigestpublic java.lang.String algName()
MessageDigestalgName in class MessageDigestpublic int getDigestLength()
MessageDigestgetDigestLength in class MessageDigestpublic byte[] getDigestBits()
getDigestBits in class MessageDigestpublic boolean isValid()
true if this PasswordBasedMAC is in a valid state and its digest bits are usable; otherwise returns false.isValid in class MessageDigestpublic java.lang.Object clone()
MessageDigestclone in class MessageDigestprotected MessageDigest.MDState getState()
MessageDigestgetState in class MessageDigestprotected void setState(MessageDigest.MDState state)
MessageDigestsetState in class MessageDigest