|
63 | 63 | import org.apache.commons.codec.binary.Hex; |
64 | 64 |
|
65 | 65 | /** |
66 | | - * Operations to simplifiy common <code>MessageDigest</code> tasks. This |
| 66 | + * Operations to simplifiy common {@link java.security.MessageDigest} tasks. This |
67 | 67 | * class is thread safe. |
68 | 68 | * |
69 | 69 | * @author Dave Dribin |
70 | 70 | * @author David Graham |
| 71 | + * @author Gary Gregory |
71 | 72 | */ |
72 | 73 | public class DigestUtils { |
73 | 74 |
|
74 | | - /** |
75 | | - * Returns an MD5 MessageDigest. |
76 | | - * |
77 | | - * @return An MD5 digest instance. |
78 | | - */ |
79 | | - private static MessageDigest getMd5Digest() { |
80 | | - try { |
81 | | - return MessageDigest.getInstance("MD5"); |
82 | | - |
83 | | - } catch (NoSuchAlgorithmException e) { |
84 | | - throw new RuntimeException(e.getMessage()); |
85 | | - } |
86 | | - } |
| 75 | + /** |
| 76 | + * Returns a MessageDigest for the given <code>algorithm</code>. |
| 77 | + * |
| 78 | + * @return An MD5 digest instance. |
| 79 | + * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught, |
| 80 | + */ |
| 81 | + protected static MessageDigest getDigest(String algorithm) { |
| 82 | + try { |
| 83 | + return MessageDigest.getInstance(algorithm); |
| 84 | + } catch (NoSuchAlgorithmException e) { |
| 85 | + throw new RuntimeException(e.getMessage()); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Returns an MD5 MessageDigest. |
| 91 | + * |
| 92 | + * @return An MD5 digest instance. |
| 93 | + * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught, |
| 94 | + */ |
| 95 | + private static MessageDigest getMd5Digest() { |
| 96 | + return getDigest("MD5"); |
| 97 | + } |
87 | 98 |
|
88 | 99 | /** |
89 | 100 | * Returns an SHA digest. |
90 | 101 | * |
91 | 102 | * @return An SHA digest instance. |
| 103 | + * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught, |
92 | 104 | */ |
93 | 105 | private static MessageDigest getShaDigest() { |
94 | | - try { |
95 | | - return MessageDigest.getInstance("SHA"); |
96 | | - |
97 | | - } catch (NoSuchAlgorithmException e) { |
98 | | - throw new RuntimeException(e.getMessage()); |
99 | | - } |
| 106 | + return getDigest("SHA"); |
100 | 107 | } |
101 | 108 |
|
102 | 109 | /** |
|
0 commit comments