%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
net.sf.mindoro.commons.util.Sha256Util |
|
|
1 | /* |
|
2 | * Created on Jun 6, 2005 |
|
3 | * |
|
4 | * A utility class to calculate SHA-256 message digests. |
|
5 | */ |
|
6 | package net.sf.mindoro.commons.util; |
|
7 | ||
8 | import java.security.MessageDigest; |
|
9 | import java.security.NoSuchAlgorithmException; |
|
10 | ||
11 | /** |
|
12 | * A utility class to calculate SHA-256 message digests. |
|
13 | * |
|
14 | * @author aisrael |
|
15 | */ |
|
16 | public final class Sha256Util { |
|
17 | ||
18 | /** |
|
19 | * Instances of Sha256Util should NOT be constructed during regular |
|
20 | * programming. |
|
21 | */ |
|
22 | 0 | private Sha256Util() { |
23 | // noop |
|
24 | 0 | } |
25 | ||
26 | /** |
|
27 | * Get the SHA-256 MessageDigest to use. |
|
28 | * |
|
29 | * @return MessageDigest |
|
30 | */ |
|
31 | private static MessageDigest getDigest() { |
|
32 | try { |
|
33 | 5 | return MessageDigest.getInstance("SHA-256"); |
34 | 0 | } catch (final NoSuchAlgorithmException e) { |
35 | 0 | throw new RuntimeException(e); |
36 | } |
|
37 | 2 | } |
38 | ||
39 | /** |
|
40 | * @param s |
|
41 | * String |
|
42 | * @return SHA-256 hash of s |
|
43 | */ |
|
44 | public static String hash(final String s) { |
|
45 | 5 | return StringUtils.toHex(getDigest().digest(s.getBytes())); |
46 | } |
|
47 | 7 | |
48 | 2 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |