public final class Checksum
extends java.lang.Object
Example:
final Checksum checksum = Checksum.create(); final int integer = 489464795; final String value = "keyToBeEncoded"; final String other = "anotherKey"; final String signature = checksum.getSha256(value); final String test = checksum.getSha256(integer); Assert.assertTrue(checksum.check(value, signature)); Assert.assertFalse(checksum.check(other, signature)); Assert.assertTrue(checksum.check(integer, test));
Modifier and Type | Method and Description |
---|---|
boolean |
check(int value,
java.lang.String signature)
Compare a checksum with its supposed original value.
|
boolean |
check(java.lang.String value,
java.lang.String signature)
Compare a checksum with its supposed original value.
|
static Checksum |
create()
Create a new checksum.
|
java.lang.String |
getSha256(byte[] bytes)
Get the SHA-256 signature of the input bytes.
|
java.lang.String |
getSha256(int i)
Get the SHA-256 signature of the input integer.
|
java.lang.String |
getSha256(java.lang.String str)
Get the SHA-256 signature of the input string.
|
public static Checksum create()
public boolean check(java.lang.String value, java.lang.String signature)
value
- The original value.signature
- The checksum value.true
if corresponding (checksum of value is equal to its signature), false
else.public boolean check(int value, java.lang.String signature)
value
- The original value.signature
- The checksum value.true
if corresponding (checksum of value is equal to its signature), false
else.public java.lang.String getSha256(byte[] bytes)
bytes
- The input bytes.public java.lang.String getSha256(int i)
i
- The input integer.public java.lang.String getSha256(java.lang.String str)
str
- The input integer.