com.jdbwc.util
Class Security

java.lang.Object
  extended by com.jdbwc.util.Security

public final class Security
extends java.lang.Object

Security methods for this package.

Version:
2010-04-10
Author:
Tim Gall

Method Summary
static java.lang.String getHash(java.lang.String algorithm, java.lang.String input)
          Generate and return a MessageDigest hash for the String input.
static java.lang.String getSecureString(java.lang.String input)
          Return a secure String based on input.
The leading chars are the salt.
static java.lang.String rand(int aListSize)
          Returns a Mixed-Character random value of given length.
static java.lang.String rand(int aListSize, boolean alphNumeric)
          Returns an AlphaNumeric random value of given length.
Suitable for user-names.
static java.lang.String rand(int aListSize, boolean alphNumericOnly, boolean numericOnly)
          Returns an AlphaNumeric random value of given length.
Suitable for user-names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSecureString

public static java.lang.String getSecureString(java.lang.String input)
                                        throws java.sql.SQLException
Return a secure String based on input.
The leading chars are the salt. This value can be reproduced on the other end from the same input string and the output from this method as long as the salt length is known on both ends.
Computationally very hard to hack and not reversible (can't be decrypted)

Parameters:
input - String to derive secure hash from.
Returns:
String - secure hash based on input.
Throws:
java.sql.SQLException

getHash

public static java.lang.String getHash(java.lang.String algorithm,
                                       java.lang.String input)
                                throws java.sql.SQLException
Generate and return a MessageDigest hash for the String input.

Parameters:
input - String to derive MessageDigest from.
algorithm - Algorithm type EG: MD5, SHA-256, SHA-512
Returns:
MessageDigest digest of input. Output as a String.
Throws:
java.sql.SQLException

rand

public static java.lang.String rand(int aListSize)
Returns a Mixed-Character random value of given length. Suitable for passwords.

Parameters:
aListSize - int - must be greater than 0.
Returns:
randomly generated string aListSize in length.

rand

public static java.lang.String rand(int aListSize,
                                    boolean alphNumeric)
Returns an AlphaNumeric random value of given length.
Suitable for user-names.

Parameters:
aListSize - int - must be greater than 0.
alphNumeric - If true, only AlphaNumeric characters are used, otherwise mixed characters are used.
Mixed characters can break username's in certain situations but are ideal for strong passwords.
Returns:
randomly generated AlphaNumeric string aListSize in length.

rand

public static java.lang.String rand(int aListSize,
                                    boolean alphNumericOnly,
                                    boolean numericOnly)
Returns an AlphaNumeric random value of given length.
Suitable for user-names.

Parameters:
aListSize - int - must be greater than 0.
alphNumericOnly - If true, only AlphaNumeric characters are used, otherwise mixed characters are used.
Mixed characters can break username's in certain situations but are ideal for strong passwords.
numericOnly - If true only numbers will be used. This takes precedent over alphNumericOnly.
Returns:
randomly generated AlphaNumeric string aListSize in length.