org.sandev.basics.util
Class SampleEncryptor

java.lang.Object
  extended by org.sandev.basics.util.SampleEncryptor
All Implemented Interfaces:
SandEncryptor

public class SampleEncryptor
extends java.lang.Object
implements SandEncryptor

A sample encryptor implementation. This creates cyphertext using the username/password information for the AuthUser.

If the AuthUser given during encryption is null, then the user ID for the resulting cyphertext will be zero, which indicates that null should be used for decryption as well.


Constructor Summary
SampleEncryptor()
          Default ctor does nothing.
 
Method Summary
 java.lang.String decrypt(AuthUser user, java.lang.String str)
          Decrypt the plaintext.
 java.lang.String encrypt(AuthUser user, java.lang.String str)
          Encrypt the plaintext.
 long getCypherUserID(java.lang.String cyphertext)
          Return the userID for the given cyphertext.
protected  int getIterationCount()
          The number of iterations used is generally recommended to be at least 1000, but this is a trade-off in terms of compute time.
protected  java.lang.String getPaddingText()
          The passphrase needs to be longer than 24 characters.
protected  byte[] getSalt(java.lang.String base)
          Return a salt value given a base string to work from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampleEncryptor

public SampleEncryptor()
Default ctor does nothing.

Method Detail

getIterationCount

protected int getIterationCount()
The number of iterations used is generally recommended to be at least 1000, but this is a trade-off in terms of compute time.


getPaddingText

protected java.lang.String getPaddingText()
The passphrase needs to be longer than 24 characters. This text fleshes it out to ensure that requirement is met.


encrypt

public java.lang.String encrypt(AuthUser user,
                                java.lang.String str)
                         throws SandEncryptorException
Encrypt the plaintext. See SandEncryptor for details.

Specified by:
encrypt in interface SandEncryptor
Throws:
SandEncryptorException

decrypt

public java.lang.String decrypt(AuthUser user,
                                java.lang.String str)
                         throws SandEncryptorException
Decrypt the plaintext. See SandEncryptor for details.

Specified by:
decrypt in interface SandEncryptor
Throws:
SandEncryptorException

getCypherUserID

public long getCypherUserID(java.lang.String cyphertext)
                     throws SandEncryptorException
Return the userID for the given cyphertext. See SandEncryptor for details.

Specified by:
getCypherUserID in interface SandEncryptor
Throws:
SandEncryptorException

getSalt

protected byte[] getSalt(java.lang.String base)
Return a salt value given a base string to work from.