public class Sha256Hash extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<Sha256Hash>
| Modifier and Type | Field and Description |
|---|---|
static int |
LENGTH |
static Sha256Hash |
ZERO_HASH |
| Constructor and Description |
|---|
Sha256Hash(byte[] rawHashBytes)
Deprecated.
|
Sha256Hash(long num,
byte[] hash) |
Sha256Hash(long num,
Sha256Hash hash) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Sha256Hash other) |
static Sha256Hash |
create(boolean isSha256,
byte[] contents)
Deprecated.
|
static Sha256Hash |
createDouble(boolean isSha256,
byte[] contents)
Deprecated.
|
boolean |
equals(java.lang.Object o) |
byte[] |
getBytes()
Returns the internal byte array, without defensively copying.
|
com.google.protobuf.ByteString |
getByteString()
For pb return ByteString.
|
static byte[] |
hash(boolean isSha256,
byte[] input)
Calculates the SHA-256 hash of the given bytes.
|
static byte[] |
hash(boolean isSha256,
byte[] input,
int offset,
int length)
Calculates the SHA-256 hash of the given byte range.
|
int |
hashCode()
Returns the last four bytes of the wrapped hash.
|
static byte[] |
hashTwice(boolean isSha256,
byte[] input)
Calculates the SHA-256 hash of the given bytes, and then hashes the resulting hash again.
|
static byte[] |
hashTwice(boolean isSha256,
byte[] input,
int offset,
int length)
Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again.
|
static byte[] |
hashTwice(boolean isSha256,
byte[] input1,
int offset1,
int length1,
byte[] input2,
int offset2,
int length2)
Calculates the hash of hash on the given byte ranges.
|
static java.security.MessageDigest |
newDigest()
Returns a new SHA-256 MessageDigest instance.
|
static org.bouncycastle.crypto.digests.SM3Digest |
newSM3Digest()
Returns a new SM3 MessageDigest instance.
|
static Sha256Hash |
of(boolean isSha256,
byte[] contents)
Creates a new instance containing the calculated (one-time) hash of the given bytes.
|
static Sha256Hash |
of(boolean isSha256,
java.io.File file)
Creates a new instance containing the calculated (one-time) hash of the given file's contents.
|
java.math.BigInteger |
toBigInteger()
Returns the bytes interpreted as a positive integer.
|
java.lang.String |
toString() |
static Sha256Hash |
twiceOf(boolean isSha256,
byte[] contents)
Creates a new instance containing the hash of the calculated hash of the given bytes.
|
static Sha256Hash |
wrap(byte[] rawHashBytes)
Creates a new instance that wraps the given hash value.
|
static Sha256Hash |
wrap(com.google.protobuf.ByteString rawHashByteString) |
public static final int LENGTH
public static final Sha256Hash ZERO_HASH
public Sha256Hash(long num,
byte[] hash)
public Sha256Hash(long num,
Sha256Hash hash)
@Deprecated public Sha256Hash(byte[] rawHashBytes)
wrap(byte[]) instead.public static Sha256Hash wrap(byte[] rawHashBytes)
rawHashBytes - the raw hash bytes to wrapjava.lang.IllegalArgumentException - if the given array length is not exactly 32public static Sha256Hash wrap(com.google.protobuf.ByteString rawHashByteString)
@Deprecated public static Sha256Hash create(boolean isSha256, byte[] contents)
of(boolean, byte[]) instead: this old name is ambiguous.public static Sha256Hash of(boolean isSha256, byte[] contents)
contents - the bytes on which the hash value is calculatedpublic static Sha256Hash of(boolean isSha256, java.io.File file) throws java.io.IOException
file - the file on which the hash value is calculatedjava.io.IOException - if an error occurs while reading the file@Deprecated public static Sha256Hash createDouble(boolean isSha256, byte[] contents)
twiceOf(boolean, byte[]) instead: this old name is ambiguous.public static Sha256Hash twiceOf(boolean isSha256, byte[] contents)
contents - the bytes on which the hash value is calculatedpublic static java.security.MessageDigest newDigest()
public static org.bouncycastle.crypto.digests.SM3Digest newSM3Digest()
public static byte[] hash(boolean isSha256,
byte[] input)
input - the bytes to hashpublic static byte[] hash(boolean isSha256,
byte[] input,
int offset,
int length)
input - the array containing the bytes to hashoffset - the offset within the array of the bytes to hashlength - the number of bytes to hashpublic static byte[] hashTwice(boolean isSha256,
byte[] input)
input - the bytes to hashpublic static byte[] hashTwice(boolean isSha256,
byte[] input,
int offset,
int length)
input - the array containing the bytes to hashoffset - the offset within the array of the bytes to hashlength - the number of bytes to hashpublic static byte[] hashTwice(boolean isSha256,
byte[] input1,
int offset1,
int length1,
byte[] input2,
int offset2,
int length2)
hashTwice(boolean,byte[]).public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.math.BigInteger toBigInteger()
public byte[] getBytes()
public com.google.protobuf.ByteString getByteString()
public int compareTo(Sha256Hash other)
compareTo in interface java.lang.Comparable<Sha256Hash>