BAEL-2501 add a new section in SHA-256 article (#6271)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.hashing;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class Keccak256HashingUnitTest {
|
||||
|
||||
private static String originalValue = "abc123";
|
||||
private static String hashedValue = "719accc61a9cc126830e5906f9d672d06eab6f8597287095a2c55a8b775e7016";
|
||||
|
||||
@Test public void testHashWithJavaMessageDigest() throws Exception {
|
||||
final String currentHashedValue = Keccak256Hashing.hashWithJavaMessageDigest(originalValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
@Test public void testHashWithBouncyCastle() {
|
||||
final String currentHashedValue = Keccak256Hashing.hashWithBouncyCastle(originalValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,24 +12,24 @@ public class SHA256HashingUnitTest {
|
||||
@Test
|
||||
public void testHashWithJavaMessageDigest() throws Exception {
|
||||
final String currentHashedValue = SHA256Hashing.HashWithJavaMessageDigest(originalValue);
|
||||
assertEquals(currentHashedValue, hashedValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashWithGuava() throws Exception {
|
||||
final String currentHashedValue = SHA256Hashing.HashWithApacheCommons(originalValue);
|
||||
assertEquals(currentHashedValue, hashedValue);
|
||||
final String currentHashedValue = SHA256Hashing.hashWithGuava(originalValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashWithApacheCommans() throws Exception {
|
||||
final String currentHashedValue = SHA256Hashing.HashWithGuava(originalValue);
|
||||
assertEquals(currentHashedValue, hashedValue);
|
||||
final String currentHashedValue = SHA256Hashing.HashWithApacheCommons(originalValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashWithBouncyCastle() throws Exception {
|
||||
final String currentHashedValue = SHA256Hashing.HashWithBouncyCastle(originalValue);
|
||||
assertEquals(currentHashedValue, hashedValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.hashing;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SHA3HashingUnitTest {
|
||||
|
||||
private static String originalValue = "abc123";
|
||||
private static String hashedValue = "f58fa3df820114f56e1544354379820cff464c9c41cb3ca0ad0b0843c9bb67ee";
|
||||
|
||||
/* works with JDK9+ only */
|
||||
//@Test
|
||||
public void testHashWithJavaMessageDigestJDK9() throws Exception {
|
||||
final String currentHashedValue = SHA3Hashing.hashWithJavaMessageDigestJDK9(originalValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashWithJavaMessageDigest() throws Exception {
|
||||
final String currentHashedValue = SHA3Hashing.hashWithJavaMessageDigest(originalValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
/* works with JDK9+ only */
|
||||
//@Test
|
||||
public void testHashWithApacheCommonsJDK9() {
|
||||
final String currentHashedValue = SHA3Hashing.hashWithApacheCommonsJDK9(originalValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashWithBouncyCastle() {
|
||||
final String currentHashedValue = SHA3Hashing.hashWithBouncyCastle(originalValue);
|
||||
assertEquals(hashedValue, currentHashedValue);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user