public class Sha256Hash extends Object implements Serializable, Comparable<Sha256Hash>
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
LENGTH
bytes
|
static Sha256Hash |
ZERO_HASH |
| 构造器和说明 |
|---|
Sha256Hash(byte[] rawHashBytes)
已过时。
|
Sha256Hash(String hexString)
已过时。
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
compareTo(Sha256Hash other) |
static Sha256Hash |
create(byte[] contents)
已过时。
|
static Sha256Hash |
createDouble(byte[] contents)
已过时。
|
boolean |
equals(Object o) |
byte[] |
getBytes()
Returns the internal byte array, without defensively copying.
|
byte[] |
getReversedBytes()
Returns a reversed copy of the internal byte array.
|
static byte[] |
hash(byte[] input)
Calculates the SHA-256 hash of the given bytes.
|
static byte[] |
hash(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(byte[] input)
Calculates the SHA-256 hash of the given bytes,
and then hashes the resulting hash again.
|
static byte[] |
hashTwice(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(byte[] input1,
int offset1,
int length1,
byte[] input2,
int offset2,
int length2) |
static MessageDigest |
newDigest()
Returns a new SHA-256 MessageDigest instance.
|
static Sha256Hash |
of(byte[] contents)
Creates a new instance containing the calculated (one-time) hash of the given bytes.
|
static Sha256Hash |
of(File file)
Creates a new instance containing the calculated (one-time) hash of the given file's contents.
|
BigInteger |
toBigInteger()
Returns the bytes interpreted as a positive integer.
|
String |
toString() |
static Sha256Hash |
twiceOf(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(String hexString)
Creates a new instance that wraps the given hash value (represented as a hex string).
|
static Sha256Hash |
wrapReversed(byte[] rawHashBytes)
Creates a new instance that wraps the given hash value, but with byte order reversed.
|
public static final int LENGTH
public static final Sha256Hash ZERO_HASH
@Deprecated public Sha256Hash(byte[] rawHashBytes)
@Deprecated public Sha256Hash(String hexString)
public static Sha256Hash wrap(byte[] rawHashBytes)
rawHashBytes - the raw hash bytes to wrapIllegalArgumentException - if the given array length is not exactly 32public static Sha256Hash wrap(String hexString)
hexString - a hash value represented as a hex stringIllegalArgumentException - if the given string is not a valid
hex string, or if it does not represent exactly 32 bytespublic static Sha256Hash wrapReversed(byte[] rawHashBytes)
rawHashBytes - the raw hash bytes to wrapIllegalArgumentException - if the given array length is not exactly 32@Deprecated public static Sha256Hash create(byte[] contents)
public static Sha256Hash of(byte[] contents)
contents - the bytes on which the hash value is calculated@Deprecated public static Sha256Hash createDouble(byte[] contents)
public static Sha256Hash twiceOf(byte[] contents)
contents - the bytes on which the hash value is calculatedpublic static Sha256Hash of(File file) throws IOException
The file contents are read fully into memory, so this method should only be used with small files.
file - the file on which the hash value is calculatedIOException - if an error occurs while reading the filepublic static MessageDigest newDigest()
This is a convenience method which wraps the checked exception that can never occur with a RuntimeException.
public static byte[] hash(byte[] input)
input - the bytes to hashpublic static byte[] hash(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(byte[] input)
input - the bytes to hashpublic static byte[] hashTwice(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(byte[] input1,
int offset1,
int length1,
byte[] input2,
int offset2,
int length2)
public int hashCode()
public BigInteger toBigInteger()
public byte[] getBytes()
public byte[] getReversedBytes()
public int compareTo(Sha256Hash other)
compareTo 在接口中 Comparable<Sha256Hash>Copyright © 2021. All rights reserved.