public class SHA1 extends Object
See RFC 3174.
Unlike MessageDigest, this implementation includes the algorithm used by
sha1dc
to detect cryptanalytic collision attacks against SHA-1, such
as the one used by SHAttered. See
sha1collisiondetection for more information.
When detectCollision is true (default), this implementation throws
Sha1CollisionException
from any digest
method if a potential collision was detected.
Modifier and Type | Method and Description |
---|---|
byte[] |
digest()
Finish the digest and return the resulting hash.
|
void |
digest(MutableObjectId id)
Finish the digest and return the resulting hash.
|
boolean |
hasCollision()
Check if a collision was detected.
|
static SHA1 |
newInstance()
Create a new context to compute a SHA-1 hash of data.
|
SHA1 |
reset()
Reset this instance to compute another hash.
|
SHA1 |
setDetectCollision(boolean detect)
Enable likely collision detection.
|
ObjectId |
toObjectId()
Finish the digest and return the resulting hash.
|
void |
update(byte b)
Update the digest computation by adding a byte.
|
void |
update(byte[] in)
Update the digest computation by adding bytes to the message.
|
void |
update(byte[] in,
int p,
int len)
Update the digest computation by adding bytes to the message.
|
public static SHA1 newInstance()
public SHA1 setDetectCollision(boolean detect)
Default is true
.
May also be set by system property:
-Dorg.eclipse.jgit.util.sha1.detectCollision=true
.
detect
- a boolean.this
public void update(byte b)
b
- a byte.public void update(byte[] in)
in
- input array of bytes.public void update(byte[] in, int p, int len)
in
- input array of bytes.p
- offset to start at from in
.len
- number of bytes to hash.public byte[] digest() throws Sha1CollisionException
Once digest()
is called, this instance should be discarded.
Sha1CollisionException
- if a collision was detected and safeHash is false.public ObjectId toObjectId() throws Sha1CollisionException
Once digest()
is called, this instance should be discarded.
Sha1CollisionException
- if a collision was detected and safeHash is false.public void digest(MutableObjectId id) throws Sha1CollisionException
Once digest()
is called, this instance should be discarded.
id
- destination to copy the digest to.Sha1CollisionException
- if a collision was detected and safeHash is false.public boolean hasCollision()
This method only returns an accurate result after the digest was obtained
through digest()
, digest(MutableObjectId)
or
toObjectId()
, as the hashing function must finish processing to
know the final state.
true
if a likely collision was detected.public SHA1 reset()
this
.Copyright © 2021 Eclipse JGit Project. All rights reserved.