Skip to content

Commit

Permalink
Add MD5 for reference
Browse files Browse the repository at this point in the history
  • Loading branch information
stianst committed Mar 18, 2024
1 parent d13193c commit a9beb95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hashing/src/main/java/HashingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ public static void main(String[] args) throws Exception {

String password = "asfdsadfsadf3498hraisduf";

List<Hash> hashes = List.of(new Pbkdf2_SHA1_27K(), new Pbkdf2_SHA512_210K(), new SCrypt(), new BCrypt(), new Argon2_12MB(), new Argon2_7MB());
List<Hash> hashes = List.of(new Pbkdf2_SHA1_27K(), new Pbkdf2_SHA512_210K(), new SCrypt(), new BCrypt(), new Argon2_12MB(), new Argon2_7MB(), new MD5());


System.out.println(String.format("%1$-25s", "Algorithm") +
String.format("%1$-12s", "Total (ms)") +
String.format("%1$-12s", "Per-hash (ms)"));

System.out.println("Processors: " + Runtime.getRuntime().availableProcessors());
System.out.println();

for (Hash hash : hashes) {
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
long start = System.currentTimeMillis();
Expand Down
19 changes: 19 additions & 0 deletions hashing/src/main/java/MD5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class MD5 implements Hash {

private static final int strength = 10;

@Override
public String hash(String key) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.digest(key.getBytes(StandardCharsets.UTF_8));
byte[] result = md5.digest();
return new String(result, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit a9beb95

Please sign in to comment.