org.pf.security.crypto
Class CryptoUtil

java.lang.Object
  extended byorg.pf.security.crypto.CryptoUtil

public class CryptoUtil
extends java.lang.Object

This utility class simplifies hashing passwords and particularly comparison of passwords.

Version:
1.0
Author:
M.Duchrow

Method Summary
 java.lang.String asPlainText(java.lang.String aString)
          Returns the given string as it is if it does not start with a prefix in curly brackets (e.g.
 byte[] createSHAhash(java.lang.String aString)
          Returns the SHA hash representation of the given string
 byte[] createSSHAhash(java.lang.String aString)
          Returns the SSHA hash representation of the given string
 byte[] createSSHAhash(java.lang.String aString, byte[] salt)
          Returns the SSHA hash representation of the given string
static CryptoUtil current()
          Returns the only instance this class supports (design pattern "Singleton")
 java.lang.String defaultEncrypted(java.lang.String aString)
          Returns the given string encrypted with the default algorithm and base64 encoded with a prefix naming the algorithm in curly brackets (e.g.
 boolean equals(java.lang.String str1, java.lang.String str2)
          Compares whether or not the two given strings are equal.
 java.lang.String shaEncrypted(java.lang.String aString)
          Returns the given string SHA encrypted and base64 encoded with a prefix "{SHA}".
 java.lang.String sshaEncrypted(java.lang.String aString)
          Returns the given string SSHA encrypted and base64 encoded with a prefix "{SSHA}".
 java.lang.String sshaEncrypted(java.lang.String aString, byte[] salt)
          Returns the given string SSHA encrypted and base64 encoded with a prefix "{SSHA}".
 byte[] xor1(java.lang.String string)
          Returns the byte array containing the xor encoded representation of the given input string.
 java.lang.String xor1Encrypted(java.lang.String aString)
          Returns the given string XOR1 encrypted and base64 encoded with a prefix "{XOR1}".
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

current

public static CryptoUtil current()
Returns the only instance this class supports (design pattern "Singleton")


asPlainText

public java.lang.String asPlainText(java.lang.String aString)
Returns the given string as it is if it does not start with a prefix in curly brackets (e.g. {xor}). If it starts with a prefix the method returns the string decrypted according to the algorithm named by the prefix.

Parameters:
aString - The string to return or to convert into plain text
Returns:
The input string unchanged or converted to plain text if it was encrypted and could be decrypted

sshaEncrypted

public java.lang.String sshaEncrypted(java.lang.String aString)
Returns the given string SSHA encrypted and base64 encoded with a prefix "{SSHA}".

Parameters:
aString - The string to be encrypted

sshaEncrypted

public java.lang.String sshaEncrypted(java.lang.String aString,
                                      byte[] salt)
Returns the given string SSHA encrypted and base64 encoded with a prefix "{SSHA}".

Parameters:
aString - The string to be encrypted
salt - The salt value

shaEncrypted

public java.lang.String shaEncrypted(java.lang.String aString)
Returns the given string SHA encrypted and base64 encoded with a prefix "{SHA}".

Parameters:
aString - The string to be encrypted

xor1Encrypted

public java.lang.String xor1Encrypted(java.lang.String aString)
Returns the given string XOR1 encrypted and base64 encoded with a prefix "{XOR1}".

Parameters:
aString - The string to be encrypted

defaultEncrypted

public java.lang.String defaultEncrypted(java.lang.String aString)
Returns the given string encrypted with the default algorithm and base64 encoded with a prefix naming the algorithm in curly brackets (e.g. {xor}).

Currently it uses the XOR encryption.


equals

public boolean equals(java.lang.String str1,
                      java.lang.String str2)
Compares whether or not the two given strings are equal. If one or both keys are encrypted then they get decrypted before being compared. That allows to compare transparently a plain text string against an XOR encrypted string or even an XOR encrypted string against a SHA hashed value. In the latter case the plain text gets hash before the comparison.


xor1

public byte[] xor1(java.lang.String string)
Returns the byte array containing the xor encoded representation of the given input string.


createSSHAhash

public byte[] createSSHAhash(java.lang.String aString)
Returns the SSHA hash representation of the given string


createSSHAhash

public byte[] createSSHAhash(java.lang.String aString,
                             byte[] salt)
Returns the SSHA hash representation of the given string

Parameters:
aString - the string to be hashed
salt - the salt value for SSHA

createSHAhash

public byte[] createSHAhash(java.lang.String aString)
Returns the SHA hash representation of the given string