src.groovy.cr.co.arquetipos.password
Class PasswordTools

java.lang.Object
  src.groovy.cr.co.arquetipos.password.PasswordTools

class PasswordTools

Encapsulates several password-related utility functions Some functions came originally from http://www.securitydocs.com/library/3439


Field Summary
private static java.lang.String allowedCharacters

private static def codec

private static java.lang.String loginCharacters

 
Constructor Summary
PasswordTools()

 
Method Summary
static boolean checkDigest(java.lang.String password, byte[] digest)

Verifies a password against a digest Value to verify byte array concatenating the 32-byte hash and the salt

static boolean checkDigestBase64(java.lang.String password, java.lang.String digestBase64)

Verifies a password against a base64-encoded digest

static boolean checkDigestHex(java.lang.String password, java.lang.String digestHex)

Verifies a password against a hex-encoded digest

private static byte[] concatenate(byte[] left, byte[] right)

Combine two byte arrays first byte array second byte array

static java.lang.String generateRandomLogin(int size = 10)

Returns a random string made up only of numbers, letters and the period character

static java.lang.String generateRandomPassword(int size = 10, def allowed = allowedCharacters)

Generates a random password out of a alowed characters

static byte[] generateSalt(int size = 4)

Generates a random salt of a certain size

static byte[] saltPassword(java.lang.String password)

SHA-256 a password and a random salt.

static java.lang.String saltPasswordBase64(java.lang.String password)

Returns a salted password base64 encoded.

static java.lang.String saltPasswordHex(java.lang.String password)

Returns a salted password hex-encoded

private static byte[][] split(byte[] src, int n)

split a byte array in two byte array to be split element at which to split the byte array

 
Methods inherited from class java.lang.Object
hashCode, getClass, equals, toString, wait, wait, wait, notify, notifyAll
 

Field Detail

allowedCharacters

private static java.lang.String allowedCharacters


codec

private static def codec


loginCharacters

private static java.lang.String loginCharacters


 
Constructor Detail

PasswordTools

PasswordTools()


 
Method Detail

checkDigest

public static boolean checkDigest(java.lang.String password, byte[] digest)
Verifies a password against a digest
param:
password Value to verify
param:
digest byte array concatenating the 32-byte hash and the salt
return:
boolean True if successful


checkDigestBase64

public static boolean checkDigestBase64(java.lang.String password, java.lang.String digestBase64)
Verifies a password against a base64-encoded digest
see:
PasswordTools#checkDigest(String,byte[])


checkDigestHex

public static boolean checkDigestHex(java.lang.String password, java.lang.String digestHex)
Verifies a password against a hex-encoded digest
see:
PasswordTools#checkDigest(String,byte[])


concatenate

private static byte[] concatenate(byte[] left, byte[] right)
Combine two byte arrays
param:
l first byte array
param:
r second byte array
return:
byte[] combined byte array


generateRandomLogin

public static java.lang.String generateRandomLogin(int size = 10)
Returns a random string made up only of numbers, letters and the period character


generateRandomPassword

public static java.lang.String generateRandomPassword(int size = 10, def allowed = allowedCharacters)
Generates a random password out of a alowed characters
param:
size Password size
param:
allowed String comprising the allowed characters
returns:
Random password


generateSalt

public static byte[] generateSalt(int size = 4)
Generates a random salt of a certain size
param:
size How many bytes should be in the salt


saltPassword

public static byte[] saltPassword(java.lang.String password)
SHA-256 a password and a random salt.
param:
password String to hash
return:
String Base64-encoded byte array concatenating the 32-byte hash and the salt


saltPasswordBase64

public static java.lang.String saltPasswordBase64(java.lang.String password)
Returns a salted password base64 encoded.
see:
PasswordTools#saltPassword(String)


saltPasswordHex

public static java.lang.String saltPasswordHex(java.lang.String password)
Returns a salted password hex-encoded
see:
PasswordTools#saltPassword(String)


split

private static byte[][] split(byte[] src, int n)
split a byte array in two
param:
src byte array to be split
param:
n element at which to split the byte array
return:
byte[][] two byte arrays that have been split


 

Groovy Documentation