@@ -89,6 +89,19 @@ public static MessageDigest getDigest(String algorithm) {
8989 }
9090 }
9191
92+ /**
93+ * Returns an MD2 MessageDigest.
94+ *
95+ * @return An MD2 digest instance.
96+ * @throws IllegalArgumentException
97+ * when a {@link NoSuchAlgorithmException} is caught, which should never happen because MD2 is a
98+ * built-in algorithm
99+ * @see MessageDigestAlgorithms#MD2
100+ */
101+ public static MessageDigest getMd2Digest () {
102+ return getDigest (MessageDigestAlgorithms .MD2 );
103+ }
104+
92105 /**
93106 * Returns an MD5 MessageDigest.
94107 *
@@ -175,6 +188,82 @@ public static MessageDigest getShaDigest() {
175188 return getDigest ("SHA" );
176189 }
177190
191+ /**
192+ * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
193+ *
194+ * @param data
195+ * Data to digest
196+ * @return MD2 digest
197+ * @since 1.7
198+ */
199+ public static byte [] md2 (byte [] data ) {
200+ return getMd2Digest ().digest (data );
201+ }
202+
203+ /**
204+ * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
205+ *
206+ * @param data
207+ * Data to digest
208+ * @return MD2 digest
209+ * @throws IOException
210+ * On error reading from the stream
211+ * @since 1.7
212+ */
213+ public static byte [] md2 (InputStream data ) throws IOException {
214+ return digest (getMd2Digest (), data );
215+ }
216+
217+ /**
218+ * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
219+ *
220+ * @param data
221+ * Data to digest
222+ * @return MD2 digest
223+ * @since 1.7
224+ */
225+ public static byte [] md2 (String data ) {
226+ return md2 (getBytesUtf8 (data ));
227+ }
228+
229+ /**
230+ * Calculates the MD2 digest and returns the value as a 32 character hex string.
231+ *
232+ * @param data
233+ * Data to digest
234+ * @return MD2 digest as a hex string
235+ * @since 1.7
236+ */
237+ public static String md2Hex (byte [] data ) {
238+ return Hex .encodeHexString (md2 (data ));
239+ }
240+
241+ /**
242+ * Calculates the MD2 digest and returns the value as a 32 character hex string.
243+ *
244+ * @param data
245+ * Data to digest
246+ * @return MD2 digest as a hex string
247+ * @throws IOException
248+ * On error reading from the stream
249+ * @since 1.7
250+ */
251+ public static String md2Hex (InputStream data ) throws IOException {
252+ return Hex .encodeHexString (md2 (data ));
253+ }
254+
255+ /**
256+ * Calculates the MD2 digest and returns the value as a 32 character hex string.
257+ *
258+ * @param data
259+ * Data to digest
260+ * @return MD2 digest as a hex string
261+ * @since 1.7
262+ */
263+ public static String md2Hex (String data ) {
264+ return Hex .encodeHexString (md2 (data ));
265+ }
266+
178267 /**
179268 * Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
180269 *
@@ -264,10 +353,12 @@ public static byte[] sha(byte[] data) {
264353 * @param data
265354 * Data to digest
266355 * @return SHA-1 digest
267- * @since 1.7
356+ * @throws IOException
357+ * On error reading from the stream
358+ * @since 1.4
268359 */
269- public static byte [] sha1 ( byte [] data ) {
270- return getSha1Digest (). digest (data );
360+ public static byte [] sha ( InputStream data ) throws IOException {
361+ return digest (getShaDigest (), data );
271362 }
272363
273364 /**
@@ -276,12 +367,9 @@ public static byte[] sha1(byte[] data) {
276367 * @param data
277368 * Data to digest
278369 * @return SHA-1 digest
279- * @throws IOException
280- * On error reading from the stream
281- * @since 1.4
282370 */
283- public static byte [] sha (InputStream data ) throws IOException {
284- return digest ( getShaDigest (), data );
371+ public static byte [] sha (String data ) {
372+ return sha ( getBytesUtf8 ( data ) );
285373 }
286374
287375 /**
@@ -290,12 +378,10 @@ public static byte[] sha(InputStream data) throws IOException {
290378 * @param data
291379 * Data to digest
292380 * @return SHA-1 digest
293- * @throws IOException
294- * On error reading from the stream
295381 * @since 1.7
296382 */
297- public static byte [] sha1 (InputStream data ) throws IOException {
298- return digest ( getSha1Digest (), data );
383+ public static byte [] sha1 (byte [] data ) {
384+ return getSha1Digest (). digest ( data );
299385 }
300386
301387 /**
@@ -304,9 +390,12 @@ public static byte[] sha1(InputStream data) throws IOException {
304390 * @param data
305391 * Data to digest
306392 * @return SHA-1 digest
393+ * @throws IOException
394+ * On error reading from the stream
395+ * @since 1.7
307396 */
308- public static byte [] sha ( String data ) {
309- return sha ( getBytesUtf8 ( data ) );
397+ public static byte [] sha1 ( InputStream data ) throws IOException {
398+ return digest ( getSha1Digest (), data );
310399 }
311400
312401 /**
0 commit comments