com.metamatrix.common.util.crypto
Class CryptoUtil

java.lang.Object
  extended by com.metamatrix.common.util.crypto.CryptoUtil

public class CryptoUtil
extends java.lang.Object

Collection of Crypto utilities and helpers for use by the server and installers.


Field Summary
static java.lang.String ENCRYPT_PREFIX
           
static java.lang.String ENCRYPTION_ENABLED
          This property indicates the encryption provider, if set to none encryption is disabled.
static java.net.URL KEY
           
static java.lang.String KEY_NAME
          The name of the key.
static java.lang.String NONE
           
static java.lang.String OLD_ENCRYPT_PREFIX
           
 
Constructor Summary
CryptoUtil()
           
 
Method Summary
static boolean canDecrypt(java.lang.String cipherText)
           
static Cryptor getCryptor()
          Construct and return a utility that can be used for either encryption or decryption.
static Decryptor getDecryptor()
          Construct and return a utility that can be used for only decryption.
static Encryptor getEncryptor()
          Construct and return a utility that can be used for only encryption.
static void init(java.net.URL keyResource)
          Initialize this factory, bound to the given keystore and keystore password.
static boolean isEncryptionEnabled()
           
static boolean isInitialized()
           
static boolean isValueEncrypted(java.lang.String value)
           
static void main(java.lang.String[] args)
           
static java.util.Properties propertyDecrypt(java.lang.String match, java.util.Properties props)
          Decrypts given set of property values based on occurrence of the property name in the match collection.
static java.util.Properties propertyDecryptEndsWith(java.lang.String pattern, java.util.Properties props)
          Decrypts given set of property values based on occurance of the property name ending in with the given pattern.
static java.util.Properties propertyEncrypt(java.lang.String match, java.util.Properties props)
          Encrypts given set of property values based on occurrence of the property name in the match collection.
static java.util.Properties propertyEncryptEndsWith(Encryptor encryptor, java.lang.String pattern, java.util.Properties props)
          Encrypts given set of property values based on occurance of the property name ending in with the given pattern, using the specified encryptor.
static java.util.Properties propertyEncryptEndsWith(java.lang.String pattern, java.util.Properties props)
          Encrypts given set of property values based on occurrence of the property name ending in with the given pattern, using the server-side encryptor.
static void reinit()
          Allows tests to reinit if necessary
static java.lang.String stringDecrypt(java.lang.String cipherText)
           
static java.lang.String stringEncrypt(java.lang.String clearText)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCRYPTION_ENABLED

public static final java.lang.String ENCRYPTION_ENABLED
This property indicates the encryption provider, if set to none encryption is disabled.

See Also:
Constant Field Values

KEY_NAME

public static final java.lang.String KEY_NAME
The name of the key.

See Also:
Constant Field Values

KEY

public static final java.net.URL KEY

OLD_ENCRYPT_PREFIX

public static final java.lang.String OLD_ENCRYPT_PREFIX
See Also:
Constant Field Values

ENCRYPT_PREFIX

public static final java.lang.String ENCRYPT_PREFIX
See Also:
Constant Field Values

NONE

public static final java.lang.String NONE
See Also:
Constant Field Values
Constructor Detail

CryptoUtil

public CryptoUtil()
Method Detail

isEncryptionEnabled

public static boolean isEncryptionEnabled()

propertyEncrypt

public static java.util.Properties propertyEncrypt(java.lang.String match,
                                                   java.util.Properties props)
                                            throws CryptoException
Encrypts given set of property values based on occurrence of the property name in the match collection.

Parameters:
match - A Set of property names that, if found in props property names, will modify the associated value in props. Note: This is a case insensitive match.
props - The properties whose values are to be modified in place.
Throws:
CryptoException - if there's an error with the Cryptor.

propertyDecrypt

public static java.util.Properties propertyDecrypt(java.lang.String match,
                                                   java.util.Properties props)
                                            throws CryptoException
Decrypts given set of property values based on occurrence of the property name in the match collection.

Parameters:
match - A Set of property names that, if found in props property names, will modify the associated value in props. Note: This is a case insensitive match.
props - The properties whose values are to be modified in place.
Throws:
CryptoException - if there's an error with the Cryptor.

propertyEncryptEndsWith

public static java.util.Properties propertyEncryptEndsWith(java.lang.String pattern,
                                                           java.util.Properties props)
                                                    throws CryptoException
Encrypts given set of property values based on occurrence of the property name ending in with the given pattern, using the server-side encryptor. This method requires that the server keystore is available.

Parameters:
pattern - A pattern that, if found at the end of a props property name, will modify the associated value in props. Note: This is a case insensitive match.
props - The properties whose values are to be modified.
Throws:
CryptoException - if there's an error with the Cryptor.

propertyEncryptEndsWith

public static java.util.Properties propertyEncryptEndsWith(Encryptor encryptor,
                                                           java.lang.String pattern,
                                                           java.util.Properties props)
                                                    throws CryptoException
Encrypts given set of property values based on occurance of the property name ending in with the given pattern, using the specified encryptor.

Parameters:
encryptor - Encryptor to use.
pattern - A pattern that, if found at the end of a props property name, will modify the associated value in props. Note: This is a case insensitive match.
props - The properties whose values are to be modified.
Throws:
CryptoException - if there's an error with the Cryptor.

propertyDecryptEndsWith

public static java.util.Properties propertyDecryptEndsWith(java.lang.String pattern,
                                                           java.util.Properties props)
                                                    throws CryptoException
Decrypts given set of property values based on occurance of the property name ending in with the given pattern.

Parameters:
pattern - A pattern that, if found at the end of a props property name, will modify the associated value in props. Note: This is a case insensitive match.
props - The properties whose values are to be modified.
Throws:
CryptoException - if there's an error with the Cryptor.

isValueEncrypted

public static boolean isValueEncrypted(java.lang.String value)

init

public static void init(java.net.URL keyResource)
                 throws CryptoException

Initialize this factory, bound to the given keystore and keystore password.
This method will initialize the cryptor with the given keystore and will not use the application classpath to find the keystore to use. The key entry name is well-known.

Parameters:
storeFilename - url to the keystore file.
storePass - The password used to unlock the keystore.
Throws:
CryptoException

getCryptor

public static Cryptor getCryptor()
                          throws CryptoException
Construct and return a utility that can be used for either encryption or decryption.

Returns:
A utility that implements the Cryptor interface
Throws:
CryptoException - If there was a problem getting the keys required to initialize the cipher, or if there was a problem initializing the cipher utility

getEncryptor

public static Encryptor getEncryptor()
                              throws CryptoException
Construct and return a utility that can be used for only encryption.

Returns:
A utility that implements the Encryptor interface
Throws:
CryptoException - If there was a problem getting the key required to initialize the cipher, or if there was a problem initializing the cipher utility

getDecryptor

public static Decryptor getDecryptor()
                              throws CryptoException
Construct and return a utility that can be used for only decryption.

Returns:
A utility that implements the Decryptor interface
Throws:
CryptoException - If there was a problem getting the key required to initialize the cipher, or if there was a problem initializing the cipher utility

stringEncrypt

public static java.lang.String stringEncrypt(java.lang.String clearText)
                                      throws CryptoException
Throws:
CryptoException

stringDecrypt

public static java.lang.String stringDecrypt(java.lang.String cipherText)
                                      throws CryptoException
Throws:
CryptoException

canDecrypt

public static boolean canDecrypt(java.lang.String cipherText)

reinit

public static void reinit()
Allows tests to reinit if necessary


isInitialized

public static boolean isInitialized()

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 2009. All Rights Reserved.