3434 */
3535public class DigestUtils {
3636
37+ private static final int STREAM_BUFFER_LENGTH = 1024 ;
38+
3739 /**
3840 * Read through an ByteBuffer and returns the digest for the data
3941 *
@@ -200,6 +202,18 @@ public static byte[] md2(final byte[] data) {
200202 return getMd2Digest ().digest (data );
201203 }
202204
205+ /**
206+ * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
207+ *
208+ * @param data
209+ * Data to digest
210+ * @return MD2 digest
211+ * @since 1.11
212+ */
213+ public static byte [] md2 (final ByteBuffer data ) {
214+ return digest (getMd2Digest (), data );
215+ }
216+
203217 /**
204218 * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
205219 *
@@ -287,66 +301,6 @@ public static byte[] md5(final byte[] data) {
287301 return getMd5Digest ().digest (data );
288302 }
289303
290- /**
291- * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
292- *
293- * @param data
294- * Data to digest
295- * @return MD2 digest
296- * @since 1.11
297- */
298- public static byte [] md2 (final ByteBuffer data ) {
299- return digest (getMd2Digest (), data );
300- }
301-
302- /**
303- * Calculates the SHA-1 digest and returns the value as a <code>byte[]</code>.
304- *
305- * @param data
306- * Data to digest
307- * @return SHA-1 digest
308- * @since 1.11
309- */
310- public static byte [] sha1 (final ByteBuffer data ) {
311- return digest (getSha1Digest (), data );
312- }
313-
314- /**
315- * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
316- *
317- * @param data
318- * Data to digest
319- * @return SHA-256 digest
320- * @since 1.11
321- */
322- public static byte [] sha256 (final ByteBuffer data ) {
323- return digest (getSha256Digest (), data );
324- }
325-
326- /**
327- * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
328- *
329- * @param data
330- * Data to digest
331- * @return SHA-384 digest
332- * @since 1.11
333- */
334- public static byte [] sha384 (final ByteBuffer data ) {
335- return digest (getSha384Digest (), data );
336- }
337-
338- /**
339- * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
340- *
341- * @param data
342- * Data to digest
343- * @return SHA-512 digest
344- * @since 1.11
345- */
346- public static byte [] sha512 (final ByteBuffer data ) {
347- return digest (getSha512Digest (), data );
348- }
349-
350304 /**
351305 * Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
352306 *
@@ -407,19 +361,19 @@ public static String md5Hex(final ByteBuffer data) {
407361 return Hex .encodeHexString (md5 (data ));
408362 }
409363
410- /**
411- * Calculates the MD5 digest and returns the value as a 32 character hex string.
412- *
413- * @param data
414- * Data to digest
415- * @return MD5 digest as a hex string
416- * @throws IOException
417- * On error reading from the stream
418- * @since 1.4
419- */
420- public static String md5Hex (final InputStream data ) throws IOException {
421- return Hex .encodeHexString (md5 (data ));
422- }
364+ /**
365+ * Calculates the MD5 digest and returns the value as a 32 character hex string.
366+ *
367+ * @param data
368+ * Data to digest
369+ * @return MD5 digest as a hex string
370+ * @throws IOException
371+ * On error reading from the stream
372+ * @since 1.4
373+ */
374+ public static String md5Hex (final InputStream data ) throws IOException {
375+ return Hex .encodeHexString (md5 (data ));
376+ }
423377
424378 /**
425379 * Calculates the MD5 digest and returns the value as a 32 character hex string.
@@ -445,19 +399,32 @@ public static byte[] sha(final byte[] data) {
445399 return sha1 (data );
446400 }
447401
402+ /**
403+ * Calculates the SHA-1 digest and returns the value as a <code>byte[]</code>.
404+ *
405+ * @param data
406+ * Data to digest
407+ * @return SHA-1 digest
408+ * @throws IOException
409+ * On error reading from the stream
410+ * @since 1.4
411+ * @deprecated Use {@link #sha1(InputStream)}
412+ */
413+ @ Deprecated
414+ public static byte [] sha (final InputStream data ) throws IOException {
415+ return sha1 (data );
416+ }
417+
448418 /**
449419 * Calculates the SHA-1 digest and returns the value as a <code>byte[]</code>.
450420 *
451421 * @param data
452422 * Data to digest
453423 * @return SHA-1 digest
454- * @throws IOException
455- * On error reading from the stream
456- * @since 1.4
457- * @deprecated Use {@link #sha1(InputStream)}
424+ * @deprecated Use {@link #sha1(String)}
458425 */
459426 @ Deprecated
460- public static byte [] sha (final InputStream data ) throws IOException {
427+ public static byte [] sha (final String data ) {
461428 return sha1 (data );
462429 }
463430
@@ -467,11 +434,10 @@ public static byte[] sha(final InputStream data) throws IOException {
467434 * @param data
468435 * Data to digest
469436 * @return SHA-1 digest
470- * @deprecated Use {@link #sha1(String)}
437+ * @since 1.7
471438 */
472- @ Deprecated
473- public static byte [] sha (final String data ) {
474- return sha1 (data );
439+ public static byte [] sha1 (final byte [] data ) {
440+ return getSha1Digest ().digest (data );
475441 }
476442
477443 /**
@@ -480,10 +446,10 @@ public static byte[] sha(final String data) {
480446 * @param data
481447 * Data to digest
482448 * @return SHA-1 digest
483- * @since 1.7
449+ * @since 1.11
484450 */
485- public static byte [] sha1 (final byte [] data ) {
486- return getSha1Digest (). digest ( data );
451+ public static byte [] sha1 (final ByteBuffer data ) {
452+ return digest ( getSha1Digest (), data );
487453 }
488454
489455 /**
@@ -576,6 +542,18 @@ public static byte[] sha256(final byte[] data) {
576542 return getSha256Digest ().digest (data );
577543 }
578544
545+ /**
546+ * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
547+ *
548+ * @param data
549+ * Data to digest
550+ * @return SHA-256 digest
551+ * @since 1.11
552+ */
553+ public static byte [] sha256 (final ByteBuffer data ) {
554+ return digest (getSha256Digest (), data );
555+ }
556+
579557 /**
580558 * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
581559 * <p>
@@ -682,6 +660,18 @@ public static byte[] sha384(final byte[] data) {
682660 return getSha384Digest ().digest (data );
683661 }
684662
663+ /**
664+ * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
665+ *
666+ * @param data
667+ * Data to digest
668+ * @return SHA-384 digest
669+ * @since 1.11
670+ */
671+ public static byte [] sha384 (final ByteBuffer data ) {
672+ return digest (getSha384Digest (), data );
673+ }
674+
685675 /**
686676 * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
687677 * <p>
@@ -788,6 +778,18 @@ public static byte[] sha512(final byte[] data) {
788778 return getSha512Digest ().digest (data );
789779 }
790780
781+ /**
782+ * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
783+ *
784+ * @param data
785+ * Data to digest
786+ * @return SHA-512 digest
787+ * @since 1.11
788+ */
789+ public static byte [] sha512 (final ByteBuffer data ) {
790+ return digest (getSha512Digest (), data );
791+ }
792+
791793 /**
792794 * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
793795 * <p>
@@ -990,6 +992,4 @@ public static MessageDigest updateDigest(final MessageDigest messageDigest, fina
990992 messageDigest .update (StringUtils .getBytesUtf8 (valueToDigest ));
991993 return messageDigest ;
992994 }
993-
994- private static final int STREAM_BUFFER_LENGTH = 1024 ;
995995}
0 commit comments