org.kuali.rice.krad.maintainablexml
Class EncryptionService

java.lang.Object
  extended by org.kuali.rice.krad.maintainablexml.EncryptionService

public class EncryptionService
extends Object

Implementation of encryption service for demonstration. This class has been copied from the base rice code but has added an old secret key that allows for data encrypted with the commons-codec 1.3 api to be decrypted with newer versions of the api. The Base64.decodeBase64 method did not decode the last two bytes correctly in 1.3 when the encoded key did not end with '=', it always defaulted those bytes to '1'

Author:
Kuali Rice Team (rice.collab@kuali.org)

Field Summary
static String ALGORITHM
           
static String HASH_ALGORITHM
           
 
Constructor Summary
EncryptionService(String key)
           
 
Method Summary
protected  void checkEnabled()
          Performs a check to see if the encryption service is enabled.
 String decrypt(String ciphertext)
           
 byte[] decryptBytes(byte[] ciphertext)
           
 String encrypt(Object valueToHide)
           
 byte[] encryptBytes(byte[] valueToHide)
           
static String generateEncodedKey()
          This method generates keys.
 SecretKey getDesKey()
           
 SecretKey getDesKeyOld()
           
 String hash(Object valueToHide)
          Hash the value by converting to a string, running the hash algorithm, and then base64'ng the results.
 boolean isEnabled()
           
 void setDesKeyOld(SecretKey desKeyOld)
           
 void setSecretKey(String secretKey)
          Sets the secretKey attribute value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALGORITHM

public static final String ALGORITHM
See Also:
Constant Field Values

HASH_ALGORITHM

public static final String HASH_ALGORITHM
See Also:
Constant Field Values
Constructor Detail

EncryptionService

public EncryptionService(String key)
                  throws Exception
Throws:
Exception
Method Detail

isEnabled

public boolean isEnabled()

encrypt

public String encrypt(Object valueToHide)
               throws GeneralSecurityException
Throws:
GeneralSecurityException

decrypt

public String decrypt(String ciphertext)
               throws GeneralSecurityException
Throws:
GeneralSecurityException

encryptBytes

public byte[] encryptBytes(byte[] valueToHide)
                    throws GeneralSecurityException
Throws:
GeneralSecurityException

decryptBytes

public byte[] decryptBytes(byte[] ciphertext)
                    throws GeneralSecurityException
Throws:
GeneralSecurityException

generateEncodedKey

public static String generateEncodedKey()
                                 throws Exception
This method generates keys. This method is implementation specific and should not be present in any general purpose interface extracted from this class.

Returns:
Throws:
Exception

setSecretKey

public void setSecretKey(String secretKey)
                  throws Exception
Sets the secretKey attribute value.

Parameters:
secretKey - The secretKey to set.
Throws:
Exception

hash

public String hash(Object valueToHide)
            throws GeneralSecurityException
Hash the value by converting to a string, running the hash algorithm, and then base64'ng the results. Returns a blank string if any problems occur or the input value is null or empty.

Throws:
GeneralSecurityException

checkEnabled

protected void checkEnabled()
Performs a check to see if the encryption service is enabled. If it is not then an IllegalStateException will be thrown.


getDesKey

public SecretKey getDesKey()
Returns:
the desKey

getDesKeyOld

public SecretKey getDesKeyOld()
Returns:
the desKeyOld

setDesKeyOld

public void setDesKeyOld(SecretKey desKeyOld)
Parameters:
desKeyOld - the desKeyOld to set


Copyright © 2005-2012 The Kuali Foundation. All Rights Reserved.