|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.osesb.utilities.encryption.JCESymmetricEncryptionHelper
public class JCESymmetricEncryptionHelper
This class contains utility methods for encryption/decryption using symmetric keys with JCE.
Construct this Class with an EncryptionProviderConfiguration or use getJCESymmetricEncryptionHelper() to get a JCEEncryptionHelper using a EncryptionProviderConfiguration file that has been configured for the framework. An EncryptionProviderConfiguration file looks like:<encryption-provider-configuration>
<providerClassName>com.sun.crypto.provider.SunJCE</providerClassName>
<encryptionAlgorithm>DES</encryptionAlgorithm>
<keyFilePath>org/osesb/utilities/encryption/test/testdata/jce.des.encryption.test.key<</keyFilePath>
</encryption-provider-configuration>
Methods in this Class include:
| Field Summary | |
|---|---|
static java.lang.String |
DEFAULT_ENCRYPTION_PROVIDER_CONFIGFILE
The default EncryptionProviderConfiguration file for JCEEncryptionHelper(s) returned by getInstance(). |
static java.lang.String |
ENCRYPTION_PROVIDER_CONFIGFILE_PROPERTY
The system property key used to set default EncryptionProviderConfiguration for JCEEncryptionHelper(s) returned by getInstance(). |
protected java.security.Key |
encryptionKey
The encryption Key as read from the location given by EncryptionProviderConfiguration, if there is a location specified. |
protected EncryptionProviderConfiguration |
encryptionProviderConfiguration
The EncryptionProviderConfiguration for this helper. |
protected static org.apache.commons.logging.Log |
log
The logging implementation for this class. |
protected java.lang.String |
thisClassName
The full name of this class. |
| Constructor Summary | |
|---|---|
JCESymmetricEncryptionHelper(EncryptionProviderConfiguration encryptionProviderConfiguration)
Creates a new instance of JCEEncryptionHelper with the EncryptionProviderConfiguration. |
|
| Method Summary | |
|---|---|
java.lang.String |
decryptBase64String(java.lang.String input)
De-encrypts a Base64 encoded String as created by encryptToBase64String(). |
byte[] |
decryptByteArray(byte[] input)
De-encrypts a byte[]. |
byte[] |
encryptByteArray(byte[] input)
Encrypts a byte[]. |
java.lang.String |
encryptToBase64String(java.lang.String input)
Encrypts an input String and returns Base64 encoded representation of the encrypted String. |
java.security.Key |
generateKey()
Generates a symmetric encryption Key (java.security.Key). |
java.security.Key |
getEncryptionKey()
Returns the encryptionKey for this helper as a java.Security.Key |
static JCESymmetricEncryptionHelper |
getJCESymmetricEncryptionHelper()
Construct and return a new instance of JCEEncryptionHelper, using the following ordered lookup: 1. |
java.lang.String |
getProvidersInfo()
Returns a human-readable description of the Providers registered with the Security object. |
static void |
main(java.lang.String[] args)
main() for sandboxing and testing. |
java.security.Key |
readKeyObjectFromFile(java.io.File file)
Reads an encryption Key (java.security.Key) from a File. |
java.security.Key |
readKeyObjectFromPath(java.lang.String path)
Reads an encryption Key (java.security.Key) from a path. |
java.security.Key |
readKeyObjectFromResource(java.lang.String resourcePath)
Reads an encryption Key (java.security.Key) from a resource in a classLoader sensitive manner. |
void |
setEncryptionKey(java.security.Key encryptionKey)
Sets the encryptionKey for this helper. |
void |
writeKeyObject(java.security.Key key,
java.io.File file)
Writes an encryption Key (java.security.Key) to a File. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static org.apache.commons.logging.Log log
protected java.lang.String thisClassName
protected EncryptionProviderConfiguration encryptionProviderConfiguration
protected java.security.Key encryptionKey
public static final java.lang.String ENCRYPTION_PROVIDER_CONFIGFILE_PROPERTY
public static final java.lang.String DEFAULT_ENCRYPTION_PROVIDER_CONFIGFILE
| Constructor Detail |
|---|
public JCESymmetricEncryptionHelper(EncryptionProviderConfiguration encryptionProviderConfiguration)
throws java.lang.Exception
encryptionProviderConfiguration - The EncryptionProviderConfiguration
object to use for this helper.
java.lang.Exception - if constructed with null EncryptionProviderConfiguration
or if there is a problem loading the encryption provider or reading the
encryption key.| Method Detail |
|---|
public java.lang.String getProvidersInfo()
public static JCESymmetricEncryptionHelper getJCESymmetricEncryptionHelper()
throws java.lang.Exception
java.lang.Exception - if an instance of JCEEncryptionHelper cannot be returned.
public java.lang.String encryptToBase64String(java.lang.String input)
throws java.lang.Exception
input - The String to encrypt.
java.lang.Exception - if called with null parameters or if there is a
problem encrypting the input or Base64 encoding the encryption result.
public java.lang.String decryptBase64String(java.lang.String input)
throws java.lang.Exception
input - The Base64 encoded representation of an encrypted String.
java.lang.Exception - if called with null parameters or if there is a
problem encountered during de-cryption.
public byte[] encryptByteArray(byte[] input)
throws java.lang.Exception
input - The byte[] to encrypt.
java.lang.Exception - if called with null parameters or if there is a
problem encrypting the byte[].
public byte[] decryptByteArray(byte[] input)
throws java.lang.Exception
input - The byte[] to de-crypt.
java.lang.Exception - if called with null parameters or if there is a
problem encountered during de-cryption.
public java.security.Key generateKey()
throws java.lang.Exception
java.lang.Exception - If there is a problem generating the Key.
public void writeKeyObject(java.security.Key key,
java.io.File file)
throws java.lang.Exception
key - The Key to write.file - The File to write the key to.
java.lang.Exception - if called with null parameters or if there is a
problem writing the Key to the File.
public java.security.Key readKeyObjectFromPath(java.lang.String path)
throws java.lang.Exception
path - The path to read the Key from.
java.lang.Exception - if called with null parameters or if there is a
problem reading the Key.
public java.security.Key readKeyObjectFromFile(java.io.File file)
throws java.lang.Exception
file - The File to read the Key from.
java.lang.Exception - if called with null parameters or if there is a
problem reading the Key from the File.
public java.security.Key readKeyObjectFromResource(java.lang.String resourcePath)
throws java.lang.Exception
resourcePath - The path to the resource to read the Key from.
java.lang.Exception - if called with null parameters or if there is a
problem reading the Key from the resource.public java.security.Key getEncryptionKey()
public void setEncryptionKey(java.security.Key encryptionKey)
encryptionKey - The java.security.Key for this helper.public static void main(java.lang.String[] args)
args - commandline arguments
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||