Package dev.gmitch215.bytebox.security
Class MessageDigest
java.lang.Object
dev.gmitch215.bytebox.security.MessageDigest
java.security.MessageDigest, which the class library does not carry, for MD5, SHA-1,
SHA-256, SHA-384 and SHA-512.
Written in Java rather than backed by SubtleCrypto.digest, because that returns a
promise and a substituted class cannot suspend. SHA-224, SHA-512/256, SHA-3 and the MD2 digest are
not provided; asking for them throws NoSuchAlgorithmException the way an unknown name does
on a JVM. Providers are not modelled: there is no getInstance(String, String) and no
getProvider, and no clone.
- Since:
- 1.0.3
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]digest()byte[]digest(byte[] input) intdigest(byte[] buf, int offset, int len) intstatic MessageDigestgetInstance(String algorithm) static booleanisEqual(byte[] a, byte[] b) voidreset()Drops everything added so far.toString()voidupdate(byte input) voidupdate(byte[] input) voidupdate(byte[] input, int offset, int len) voidupdate(ByteBuffer input)
-
Method Details
-
getInstance
- Parameters:
algorithm- a name such asSHA-256, in any case, or one of the JDK's aliases- Returns:
- a digest that has taken no input
- Throws:
NoSuchAlgorithmException- when the algorithm is not one of the five
-
update
public void update(byte input) - Parameters:
input- the byte to add
-
update
public void update(byte[] input) - Parameters:
input- the bytes to add
-
update
public void update(byte[] input, int offset, int len) - Parameters:
input- the array to read fromoffset- where in it to startlen- how many bytes to add
-
update
- Parameters:
input- the buffer to drain from its position to its limit
-
digest
public byte[] digest()- Returns:
- the digest of everything added, after which this is as new
-
digest
public byte[] digest(byte[] input) - Parameters:
input- the last bytes to add- Returns:
- the digest of everything added, after which this is as new
-
digest
- Parameters:
buf- where to put the digestoffset- where in it to startlen- how much room to use, at least the digest length- Returns:
- the number of bytes written
- Throws:
DigestException- whenlenis shorter than the digest
-
reset
public void reset()Drops everything added so far. -
getAlgorithm
- Returns:
- the name this was asked for, as given
-
getDigestLength
public int getDigestLength()- Returns:
- the digest length in bytes
-
isEqual
public static boolean isEqual(byte[] a, byte[] b) - Parameters:
a- one digest, or nullb- another, or null- Returns:
- whether they are equal, without stopping at the first difference
-
toString
-