com.waveset.util
Class CryptoUtil

java.lang.Object
  extended bycom.waveset.util.CryptoUtil

public class CryptoUtil
extends java.lang.Object

A bag of utilities.


Field Summary
static java.lang.String code_id
           
 
Constructor Summary
CryptoUtil()
           
 
Method Summary
static void confirmJCE()
           
static byte[] generateMAC(byte[] data, byte[] secretKey)
          Generate a message digest based on a secret key with the default algorithm.
static byte[] generateMD5Hash(byte[] data)
          Creates an initialized MD5 Message Digest, updates it with the byte array data passed in, completes the hash computation, resets the digest, and then returns the one-way hash.
static byte[] generatePBEKey(char[] password)
          Generate key using PBEWithMD5andDES algorithm
static byte[] generateSHA1Hash(byte[] data)
          Creates an initialized SHA-1 Message Digest, updates it with the byte array data passed in, completes the hash computation, resets the digest, and then returns the one-way hash.
static javax.crypto.Mac getMacInstance()
          Generate a secure MAC based on the default algorithm.
static javax.crypto.Mac getMacInstance(java.lang.String algorithm)
          Generate a secure MAC based on a the specified algorithm.
static javax.crypto.spec.SecretKeySpec getSecretKeySpec(byte[] secretKey)
          Generate a secret key spec based on the default algorithm.
static javax.crypto.spec.SecretKeySpec getSecretKeySpec(byte[] secretKey, java.lang.String algo)
          Generate a secret key spec based on the specified algorithm.
static boolean isMD5HashEqual(byte[] hash1, byte[] hash2)
          Compares two digests for equality (byte array compare)
static java.lang.String md5HashtoString(byte[] data)
          Base64 encodes an MD5 hash byte array to an ascii string
static byte[] stringToMD5Hash(java.lang.String hashstr)
          Base64 decodes a string, which was previously encoded, returning the MD5 hash byte array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values
Constructor Detail

CryptoUtil

public CryptoUtil()
Method Detail

generateMD5Hash

public static byte[] generateMD5Hash(byte[] data)
                              throws WavesetException
Creates an initialized MD5 Message Digest, updates it with the byte array data passed in, completes the hash computation, resets the digest, and then returns the one-way hash. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

Throws:
WavesetException

generateSHA1Hash

public static byte[] generateSHA1Hash(byte[] data)
                               throws WavesetException
Creates an initialized SHA-1 Message Digest, updates it with the byte array data passed in, completes the hash computation, resets the digest, and then returns the one-way hash. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

Throws:
WavesetException

isMD5HashEqual

public static boolean isMD5HashEqual(byte[] hash1,
                                     byte[] hash2)
                              throws WavesetException
Compares two digests for equality (byte array compare)

Throws:
WavesetException

md5HashtoString

public static java.lang.String md5HashtoString(byte[] data)
Base64 encodes an MD5 hash byte array to an ascii string


stringToMD5Hash

public static byte[] stringToMD5Hash(java.lang.String hashstr)
                              throws WavesetException
Base64 decodes a string, which was previously encoded, returning the MD5 hash byte array

Throws:
WavesetException

generateMAC

public static byte[] generateMAC(byte[] data,
                                 byte[] secretKey)
                          throws WavesetException
Generate a message digest based on a secret key with the default algorithm.

Throws:
WavesetException

generatePBEKey

public static byte[] generatePBEKey(char[] password)
                             throws java.security.NoSuchAlgorithmException,
                                    java.security.spec.InvalidKeySpecException
Generate key using PBEWithMD5andDES algorithm

Throws:
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException

confirmJCE

public static void confirmJCE()
                       throws ConfigurationError
Throws:
ConfigurationError: - Make sure there is a JCE available. This should always pass since we require 1.4.2. This method might throw an exception:
  • if the JCE provider is removed;
  • the user wants to use the Cryptix Provider (which is no longer supported).
ConfigurationError

getSecretKeySpec

public static javax.crypto.spec.SecretKeySpec getSecretKeySpec(byte[] secretKey)
                                                        throws ConfigurationError
Generate a secret key spec based on the default algorithm.

Throws:
ConfigurationError

getSecretKeySpec

public static javax.crypto.spec.SecretKeySpec getSecretKeySpec(byte[] secretKey,
                                                               java.lang.String algo)
                                                        throws ConfigurationError
Generate a secret key spec based on the specified algorithm.

Throws:
ConfigurationError

getMacInstance

public static javax.crypto.Mac getMacInstance()
                                       throws WavesetException
Generate a secure MAC based on the default algorithm.

Throws:
WavesetException

getMacInstance

public static javax.crypto.Mac getMacInstance(java.lang.String algorithm)
                                       throws ConfigurationError
Generate a secure MAC based on a the specified algorithm.

Throws:
ConfigurationError