Modifier and Type | Field and Description |
---|---|
static char |
SEPARATOR
Character to divide algorithm name and parameter
|
static java.lang.String |
STR_SEPARATOR
String to divide algorithm name and parameter
|
Constructor and Description |
---|
MessageDigest(DigestInterface digest)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
void |
clean()
clean all object content.
|
java.lang.Object |
clone()
Returns a clone if the implementation is cloneable.
|
byte[] |
digest()
Completes the hash computation by performing final operations
such as padding.
|
byte[] |
digest(byte[] input)
Performs a final update on the digest using the specified array
of bytes, then completes the digest computation.
|
int |
digest(byte[] result,
int offset,
int length)
Completes the hash computation by performing final operations.
|
static byte[] |
digestBuffer(java.lang.String algorithm,
byte[] data,
java.security.spec.AlgorithmParameterSpec p)
Helper.
|
static byte[] |
digestBuffer(java.lang.String algorithm,
byte[] data,
int offset,
int length,
java.security.spec.AlgorithmParameterSpec p)
Helper.
|
static byte[] |
digestFile(java.lang.String algorithm,
java.io.File file)
Helper. read and hash file.
|
java.lang.String |
getAlgorithm()
get algorithm name.
|
int |
getDigestLength()
get hash function value length in bytes
|
static MessageDigest |
getInstance(java.lang.String algorithm)
Algorithm factory, create object by algorithm name.
|
static MessageDigest |
getInstance(java.lang.String algorithm,
java.security.Provider provider)
Algorithm factory, create object by algorithm name.
|
static MessageDigest |
getInstance(java.lang.String algorithm,
java.lang.String provider)
Algorithm factory, create object by algorithm name.
|
java.security.spec.AlgorithmParameterSpec |
getParameter()
get algorithm parameter.
|
long |
getProcessedLength()
Get total amount of processed bytes from reset().
|
java.security.Provider |
getProvider()
Returns the provider of this object.
|
static boolean |
isEqual(byte[] digestA,
byte[] digestB)
Compares two digests for equality.
|
void |
reset()
Resets the digest for further use.
|
void |
setParameter(java.security.spec.AlgorithmParameterSpec p)
get algorithm parameter.
|
java.lang.String |
toString()
Returns a string representation of this message digest object.
|
void |
update(byte input)
Updates the digest using the specified byte.
|
void |
update(byte[] data)
Updates the digest using the specified array of bytes.
|
void |
update(byte[] input,
int offset,
int length)
Updates the digest using the specified array of bytes, starting at the specified offset.
|
void |
update(java.nio.ByteBuffer input)
Update the digest using the specified ByteBuffer.
|
public static final char SEPARATOR
public static final java.lang.String STR_SEPARATOR
public MessageDigest(DigestInterface digest)
digest
- implementationpublic static MessageDigest getInstance(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
MessageDigest.getInstance(String)
.
Algorithm parameter can be set here "Gost3411/1.2.643.2.2.30.1".algorithm
- algorithm name.java.security.NoSuchAlgorithmException
- if the specified algorithm is not availablepublic static MessageDigest getInstance(java.lang.String algorithm, java.lang.String provider) throws java.security.NoSuchAlgorithmException
MessageDigest.getInstance(String)
.
Algorithm parameter can be set here "Gost3411/1.2.643.2.2.30.1".algorithm
- algorithm name.provider
- unusedjava.security.NoSuchAlgorithmException
- if the specified algorithm is not availablepublic static MessageDigest getInstance(java.lang.String algorithm, java.security.Provider provider) throws java.security.NoSuchAlgorithmException
MessageDigest.getInstance(String)
.
Algorithm parameter can be set here "Gost3411/1.2.643.2.2.30.1".algorithm
- algorithm name.provider
- unusedjava.security.NoSuchAlgorithmException
- if the specified algorithm is not availablepublic java.lang.String getAlgorithm()
public java.security.Provider getProvider()
public int getDigestLength()
public void reset()
public java.security.spec.AlgorithmParameterSpec getParameter()
public void setParameter(java.security.spec.AlgorithmParameterSpec p) throws java.security.InvalidAlgorithmParameterException
p
- algorithm parameter.java.security.InvalidAlgorithmParameterException
- unsuitable parameterpublic long getProcessedLength()
public void update(byte input)
input
- the byte with which to update the digest.public void update(byte[] data)
data
- the array of bytes.public void update(byte[] input, int offset, int length)
input
- the array of bytes.offset
- the offset to start from in the array of bytes.length
- the number of bytes to use, starting at offset
.public void update(java.nio.ByteBuffer input)
input.remaining()
bytes starting
at input.position()
.
Upon return, the buffer's position will be equal to its limit;
its limit will not have changed.input
- the ByteBufferpublic byte[] digest()
public byte[] digest(byte[] input)
update(input)
,
passing the input array to the update
method,
then calls digest()
.input
- the input to be updated before the digest is completed.public int digest(byte[] result, int offset, int length)
result
- output buffer for the computed digestoffset
- offset into the output buffer to begin storing the digestlength
- number of bytes within result allotted for the digestresult
public static boolean isEqual(byte[] digestA, byte[] digestB)
digestA
- one of the digests to compare.digestB
- the other digest to compare.public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if this is called on an
implementation that does not support Cloneable
.public java.lang.String toString()
toString
in class java.lang.Object
public static byte[] digestBuffer(java.lang.String algorithm, byte[] data, java.security.spec.AlgorithmParameterSpec p) throws java.security.NoSuchAlgorithmException
algorithm
- algorithm namedata
- input data.p
- AlgorithmParameterSpecjava.security.NoSuchAlgorithmException
- invalid algorithm namepublic static byte[] digestBuffer(java.lang.String algorithm, byte[] data, int offset, int length, java.security.spec.AlgorithmParameterSpec p) throws java.security.NoSuchAlgorithmException
algorithm
- algorithm namedata
- input data.offset
- offset in data
.length
- length of processed bytes in data
.p
- AlgorithmParameterSpecjava.security.NoSuchAlgorithmException
- invalid algorithm namepublic static byte[] digestFile(java.lang.String algorithm, java.io.File file) throws java.io.IOException, java.security.NoSuchAlgorithmException
algorithm
- algorithm namefile
- filejava.io.IOException
- if IO error occurred.java.security.NoSuchAlgorithmException
- invalid algorithm name