org.n52.security.common.crypto
Class DigestUtil

java.lang.Object
  extended by org.n52.security.common.crypto.DigestUtil

public final class DigestUtil
extends java.lang.Object

Class DigestUtil contains some convenient utility methods related to MessageDigest tasks.

Version:
: $
Author:
Marko Reiprecht Created on 19.09.2007

Method Summary
static char[] digestToCharArray(byte[] digest)
          Method digestToCharArray converts a byte[] message digest to its two digit hexdecimal representation as chars.
static java.lang.String digestToString(byte[] digest)
          Method digestToString converts a byte[] message digest to its two digit hexdecimal representation as string.
static boolean isDigestOf(byte[] digest, int expectedSize)
          Method isDigestOf test if the given byte[] array is a digest.
static boolean isDigestOf(byte[] digest, java.security.MessageDigest algorithm)
          Method isDigestOf test if the given byte[] array is a digest.
static boolean isDigestOf(byte[] digest, java.lang.String algorithm)
          Method isDigestOf test if the given byte[] array is a digest.
static boolean isDigestOf(char[] digest, int expectedSize)
          Method isDigestOf test if the given char[] array is a digest.
static boolean isDigestOf(char[] digest, java.security.MessageDigest algorithm)
          Method isDigestOf test if the given char[] array is a digest.
static boolean isDigestOf(char[] digest, java.lang.String algorithm)
          Method isDigestOf test if the given char[] array is a digest.
static boolean isDigestOf(java.lang.String digest, int expectedSize)
          Method isDigestOf test if the given String is a digest.
static boolean isDigestOf(java.lang.String digest, java.security.MessageDigest algorithm)
          Method isDigestOf test if the given char[] array is a digest.
static boolean isDigestOf(java.lang.String digest, java.lang.String algorithm)
          Method isDigestOf test if the given char[] array is a digest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

digestToString

public static java.lang.String digestToString(byte[] digest)
Method digestToString converts a byte[] message digest to its two digit hexdecimal representation as string.

Parameters:
digest - the digest !=null.
Returns:
String.

digestToCharArray

public static char[] digestToCharArray(byte[] digest)
Method digestToCharArray converts a byte[] message digest to its two digit hexdecimal representation as chars.

Parameters:
digest - the digest !=null.
Returns:
char[].

isDigestOf

public static boolean isDigestOf(byte[] digest,
                                 int expectedSize)
Method isDigestOf test if the given byte[] array is a digest. This simple tests for the correct length and is only supplied for convenience.

Parameters:
digest - the digest !=null
expectedSize - the expectedSize.
Returns:
boolean.

isDigestOf

public static boolean isDigestOf(char[] digest,
                                 int expectedSize)
Method isDigestOf test if the given char[] array is a digest. This tests the correct length and if all chars are in a hexadecimal range.

The expectedSize must be the length of the digest in bytes, not in chars!

Parameters:
digest - the digest !=null.
expectedSize - the expectedSize of the digest in bytes as given by the algoritm MessageDigest.getDigestLength() Therewith this is the size in bytes, not the size of the char array, e.g. MD5 has a size of 16, and the char[] is tested for a length of 32.
Returns:
boolean.

isDigestOf

public static boolean isDigestOf(java.lang.String digest,
                                 int expectedSize)
Method isDigestOf test if the given String is a digest. This tests the correct length and if all chars are in a hexadecimal range.

The expectedSize must be the length of the digest in bytes, not in chars!

Parameters:
digest - the digest !=null.
expectedSize - the expectedSize of the digest in bytes as given by the algoritm MessageDigest.getDigestLength() Therewith this is the size in bytes, not the size of the String, e.g. MD5 has a size of 16, and the String is tested for a length of 32.
Returns:
boolean.

isDigestOf

public static boolean isDigestOf(byte[] digest,
                                 java.security.MessageDigest algorithm)
Method isDigestOf test if the given byte[] array is a digest. This simple tests for the correct length and is only supplied for convenience.

Parameters:
digest - the digest !=null.
algorithm - the algorithm !=null.
Returns:
boolean.

isDigestOf

public static boolean isDigestOf(char[] digest,
                                 java.security.MessageDigest algorithm)
Method isDigestOf test if the given char[] array is a digest. This tests the correct length and if all chars are in a hexadecimal range.

Parameters:
digest - the digest !=null.
algorithm - the algorithm !=null.
Returns:
boolean.

isDigestOf

public static boolean isDigestOf(java.lang.String digest,
                                 java.security.MessageDigest algorithm)
Method isDigestOf test if the given char[] array is a digest. This tests the correct length and if all chars are in a hexadecimal range.

Parameters:
digest - the digest !=null.
algorithm - the algorithm !=null.
Returns:
boolean.

isDigestOf

public static boolean isDigestOf(byte[] digest,
                                 java.lang.String algorithm)
                          throws java.security.NoSuchAlgorithmException
Method isDigestOf test if the given byte[] array is a digest. This simple tests for the correct length and is only supplied for convenience.

Parameters:
digest - the digest !=null.
algorithm - the algorithm !=null.
Returns:
boolean.
Throws:
java.security.NoSuchAlgorithmException - if algorithm not supported.

isDigestOf

public static boolean isDigestOf(char[] digest,
                                 java.lang.String algorithm)
                          throws java.security.NoSuchAlgorithmException
Method isDigestOf test if the given char[] array is a digest. This tests the correct length and if all chars are in a hexadecimal range.

Parameters:
digest - the digest !=null.
algorithm - the method !=null.
Returns:
boolean.
Throws:
java.security.NoSuchAlgorithmException - if algorithm not supported.

isDigestOf

public static boolean isDigestOf(java.lang.String digest,
                                 java.lang.String algorithm)
                          throws java.security.NoSuchAlgorithmException
Method isDigestOf test if the given char[] array is a digest. This tests the correct length and if all chars are in a hexadecimal range.

Parameters:
digest - the digest !=null.
algorithm - the method !=null.
Returns:
boolean.
Throws:
java.security.NoSuchAlgorithmException - if algorithm not supported.


Copyright © 2004-2009 52north.org. All Rights Reserved.