org.lsc.utils.security
Class SymmetricEncryption

java.lang.Object
  extended by org.lsc.utils.security.SymmetricEncryption

public class SymmetricEncryption
extends Object

This new class allows symmetric encryption. You should have BouncyCastle installed. Three new configuration parameters could be added to the configuration:


Field Summary
static String DEFAULT_CIPHER_ALGORITHM
           
static int DEFAULT_CIPHER_STRENGTH
           
 
Constructor Summary
SymmetricEncryption()
          New SymmetricEncryption object with default values.
SymmetricEncryption(String keyPath, String algo, int strength)
          New SymmetricEncryption object.
 
Method Summary
 byte[] decrypt(byte[] toDecrypt)
          Decrypt bytes.
 byte[] encrypt(byte[] toEncrypt)
          Encrypt bytes.
 boolean generateDefaultRandomKeyFile()
          Generate a random key file with default value
 boolean generateRandomKeyFile(String keyPath, String algo, int strength)
          Generate a random key file.
static String getDefaultAlgorithm()
          Return the default supported algorithm to use.
static String getDefaultKeyPath()
          Return the default filename of the key to use.
static int getDefaultStrength()
          Return the default encryption strength.
 boolean initialize()
          Initialize encryption object from the configuration file.
static void main(String[] argv)
          This main allow user to generate random key file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CIPHER_STRENGTH

public static final int DEFAULT_CIPHER_STRENGTH
See Also:
Constant Field Values

DEFAULT_CIPHER_ALGORITHM

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

SymmetricEncryption

public SymmetricEncryption()
                    throws GeneralSecurityException
New SymmetricEncryption object with default values.

Throws:
GeneralSecurityException

SymmetricEncryption

public SymmetricEncryption(String keyPath,
                           String algo,
                           int strength)
                    throws GeneralSecurityException
New SymmetricEncryption object.

Parameters:
keyPath - The filename of the key to use
algo - A supported algorithm to use (see constant values defined in this class which specified supported algorithms)
strength - The encryption strength
Throws:
GeneralSecurityException
Method Detail

encrypt

public byte[] encrypt(byte[] toEncrypt)
               throws GeneralSecurityException
Encrypt bytes.

Parameters:
toEncrypt -
Returns:
Encrypted bytes.
Throws:
GeneralSecurityException

decrypt

public byte[] decrypt(byte[] toDecrypt)
               throws GeneralSecurityException
Decrypt bytes.

Parameters:
toDecrypt -
Returns:
Decrypted bytes.
Throws:
GeneralSecurityException

generateDefaultRandomKeyFile

public boolean generateDefaultRandomKeyFile()
                                     throws NoSuchAlgorithmException,
                                            NoSuchProviderException
Generate a random key file with default value

Returns:
boolean false if an error occurred
Throws:
NoSuchAlgorithmException
NoSuchProviderException

generateRandomKeyFile

public boolean generateRandomKeyFile(String keyPath,
                                     String algo,
                                     int strength)
                              throws NoSuchAlgorithmException,
                                     NoSuchProviderException
Generate a random key file.

Parameters:
keyPath - The filename where to write the key
algo - The supported algorithm to use
strength - The encryption strength
Returns:
boolean false if an error occurred
Throws:
NoSuchAlgorithmException
NoSuchProviderException

getDefaultKeyPath

public static String getDefaultKeyPath()
Return the default filename of the key to use. The filename could be specified in the configuration file through the lsc.security.encryption.keyfile property.

Returns:
A filename

getDefaultAlgorithm

public static String getDefaultAlgorithm()
Return the default supported algorithm to use. The algorithm could be specified in the configuration file through the lsc.security.encryption.algorithm property. See constant values defined in this class which specified supported algorithms.

Returns:
A supported algorithm

getDefaultStrength

public static int getDefaultStrength()
Return the default encryption strength. The encryption strength could be specified in the configuration file through the lsc.security.encryption.strength property.

Returns:
int

initialize

public boolean initialize()
                   throws GeneralSecurityException
Initialize encryption object from the configuration file.

Returns:
boolean (always true if no exception)
Throws:
GeneralSecurityException

main

public static void main(String[] argv)
This main allow user to generate random key file.

Parameters:
argv -


Copyright © 2005-2010 LSC project. All Rights Reserved.