Package com.palantir.util.crypto
Class Sha256Hash
- java.lang.Object
-
- com.palantir.util.crypto.Sha256Hash
-
- All Implemented Interfaces:
Serializable
,Comparable<Sha256Hash>
public class Sha256Hash extends Object implements Serializable, Comparable<Sha256Hash>
A SHA-256 hash. This class provides type-safety and equals/hashCode implementations.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Sha256Hash
EMPTY
The hash of an empty byte array, which can be used as a sentinel value.
-
Constructor Summary
Constructors Constructor Description Sha256Hash(byte[] bytes)
Constructs a type-safeSha256Hash
object from the given hash bytes.Sha256Hash(com.google.common.hash.HashCode hashCode)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Sha256Hash o)
static Sha256Hash
computeHash(byte[] bytes)
Computes the SHA-256 hash for the given array of bytes.static Sha256Hash
createFrom(InputStream is)
This method will read all the bytes in the stream and digest them.static Sha256Hash
createFrom(MessageDigest digest)
static Sha256Hash
deSerializeFromBase64String(String s)
static Sha256Hash
deSerializeFromHexString(String s)
boolean
equals(Object obj)
byte[]
getBytes()
static MessageDigest
getMessageDigest()
Returns aMessageDigest
for computing SHA-256 hashes.com.google.common.hash.Hasher
hash(com.google.common.hash.Hasher hasher)
int
hashCode()
String
serializeToBase64String()
String
serializeToHexString()
String
toString()
-
-
-
Field Detail
-
EMPTY
public static final Sha256Hash EMPTY
The hash of an empty byte array, which can be used as a sentinel value.
-
-
Constructor Detail
-
Sha256Hash
public Sha256Hash(byte[] bytes)
Constructs a type-safeSha256Hash
object from the given hash bytes. The given byte array must be exactly 256 bits (32 bytes) in length.
-
Sha256Hash
public Sha256Hash(com.google.common.hash.HashCode hashCode)
-
-
Method Detail
-
createFrom
public static Sha256Hash createFrom(MessageDigest digest)
-
createFrom
public static Sha256Hash createFrom(InputStream is) throws IOException
This method will read all the bytes in the stream and digest them. It will attempt to close the stream as well.- Throws:
IOException
-
hash
public com.google.common.hash.Hasher hash(com.google.common.hash.Hasher hasher)
-
serializeToBase64String
public String serializeToBase64String()
-
deSerializeFromBase64String
public static Sha256Hash deSerializeFromBase64String(String s)
-
serializeToHexString
public String serializeToHexString()
-
deSerializeFromHexString
public static Sha256Hash deSerializeFromHexString(String s)
-
getBytes
public byte[] getBytes()
-
getMessageDigest
public static MessageDigest getMessageDigest()
Returns aMessageDigest
for computing SHA-256 hashes.
-
computeHash
public static Sha256Hash computeHash(byte[] bytes)
Computes the SHA-256 hash for the given array of bytes.
-
compareTo
public int compareTo(Sha256Hash o)
- Specified by:
compareTo
in interfaceComparable<Sha256Hash>
-
-