1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.qa.glnm.format;
21
22 import java.nio.charset.StandardCharsets;
23 import java.security.MessageDigest;
24 import java.security.NoSuchAlgorithmException;
25 import java.util.Base64;
26
27 import org.apache.commons.codec.digest.MessageDigestAlgorithms;
28
29 import io.wcm.qa.glnm.exceptions.GaleniumException;
30
31 final class Md5Util {
32
33 private Md5Util() {
34
35 }
36
37
38
39
40
41
42
43
44 public static String getMd5AsAscii(byte[] input) {
45 try {
46 MessageDigest digest = MessageDigest.getInstance(MessageDigestAlgorithms.MD5);
47 byte[] digestedBytes = digest.digest(input);
48 return getBytesAsAscii(digestedBytes);
49 }
50 catch (NoSuchAlgorithmException ex) {
51 throw new GaleniumException("Java not remembering MD5.", ex);
52 }
53 }
54
55 private static String getBytesAsAscii(byte[] bytesToEncode) {
56 byte[] encodedBytes = Base64.getEncoder().encode(bytesToEncode);
57 return new String(encodedBytes, StandardCharsets.US_ASCII);
58 }
59
60 }