com.bankframe.util
Class Cryptography

java.lang.Object
  extended bycom.bankframe.util.Cryptography

public class Cryptography
extends java.lang.Object

This class provides a wrapper around the Java Cryptography API. This class contains methods to generate an encryption key, wrap an encryption key byte array, encrypt data and decrypt data. The user can specify the encryption algorithm and provider to use. This class requires the Java Cryptography API jars to run.


Constructor Summary
Cryptography()
          Constructor
 
Method Summary
static byte[] asciiArrayToByteArray(byte[] bytes)
          This method converts an array of ascii characters into the actual values that the ascii characters represent.
static byte[] byteArrayToCharArray(byte[] bytes)
          This method converts an array of actual values into their ascii character representation.
static byte[] decrypt(byte[] encryptedData, javax.crypto.SecretKey masterKey, java.lang.String algorithm)
          This method decrypts the specified data
static byte[] decrypt(byte[] encryptedData, javax.crypto.SecretKey masterKey, java.lang.String algorithm, java.lang.String provider)
          This method decrypts the specified data using the specified algorithm.
static byte[] encrypt(byte[] rawData, javax.crypto.SecretKey masterKey, java.lang.String algorithm)
          This method encrypts the specified data
static byte[] encrypt(byte[] rawData, javax.crypto.SecretKey masterKey, java.lang.String algorithm, java.lang.String provider)
          This method encrypts the specified data using the specified algorithm.
static javax.crypto.SecretKey generateEncryptionKey(java.lang.String algorithm, int keysize)
          This method generates a symetric encryption key using the specified algorithm.
static javax.crypto.SecretKey generateEncryptionKey(java.lang.String algorithm, java.lang.String provider, int keysize)
          This method generates a symetric encryption key using the specified algorithm and provider.
static javax.crypto.SecretKey wrapEncryptionKey(byte[] theEncryptionKey, java.lang.String algorithm)
          This method wraps the specified symetric encryption key bytes into a SecretKey for use by the Java Cryptography API.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cryptography

public Cryptography()
Constructor

Method Detail

generateEncryptionKey

public static javax.crypto.SecretKey generateEncryptionKey(java.lang.String algorithm,
                                                           java.lang.String provider,
                                                           int keysize)
                                                    throws java.security.NoSuchProviderException,
                                                           java.security.NoSuchAlgorithmException
This method generates a symetric encryption key using the specified algorithm and provider. If the SunJCE provider is specified then the SunJCE security provider is added.

Parameters:
algorithm - is the name of the Encryption algorithm, e.g. DES
provider - is the name of the provider to use, e.g. SunJCE
keysize - is an algorithm-specific metric, specified in number of bits. e.g. 56 for Des encryption key
Returns:
the generated SecretKey.
Throws:
java.security.NoSuchAlgorithmException - if a particular cryptographic algorithm is requested but is not available in the environment
java.security.NoSuchProviderException - if a particular security provider is requested but is not available in the environment

generateEncryptionKey

public static javax.crypto.SecretKey generateEncryptionKey(java.lang.String algorithm,
                                                           int keysize)
                                                    throws java.security.NoSuchProviderException,
                                                           java.security.NoSuchAlgorithmException
This method generates a symetric encryption key using the specified algorithm.

Parameters:
algorithm - is the name of the Encryption algorithm, e.g. DES
keysize - is an algorithm-specific metric, specified in number of bits. e.g. 56 for Des encryption key
Returns:
the generated SecretKey.
Throws:
java.security.NoSuchAlgorithmException - if a particular cryptographic algorithm is requested but is not available in the environment
java.security.NoSuchProviderException

wrapEncryptionKey

public static javax.crypto.SecretKey wrapEncryptionKey(byte[] theEncryptionKey,
                                                       java.lang.String algorithm)
                                                throws java.security.InvalidKeyException,
                                                       java.security.NoSuchAlgorithmException,
                                                       java.security.spec.InvalidKeySpecException
This method wraps the specified symetric encryption key bytes into a SecretKey for use by the Java Cryptography API.

Parameters:
theEncryptionKey - is the bytes to wrap into a Secret key
algorithm - is the algorithm to use, e.g. DES
Returns:
the wrapped SecretKey.
Throws:
java.security.NoSuchAlgorithmException - if a particular cryptographic algorithm is requested but is not available in the environment
java.security.InvalidKeyException - for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
java.security.spec.InvalidKeySpecException - for invalid key specifications
java.security.NoSuchProviderException - if a particular security provider is requested but is not available in the environment
javax.crypto.IllegalBlockSizeException - if the length of data provided to a block cipher is incorrect, i.e., does not match the block size of the cipher

encrypt

public static byte[] encrypt(byte[] rawData,
                             javax.crypto.SecretKey masterKey,
                             java.lang.String algorithm,
                             java.lang.String provider)
                      throws javax.crypto.NoSuchPaddingException,
                             java.security.NoSuchAlgorithmException,
                             java.security.InvalidKeyException,
                             javax.crypto.BadPaddingException,
                             java.security.NoSuchProviderException,
                             javax.crypto.IllegalBlockSizeException
This method encrypts the specified data using the specified algorithm.

Parameters:
rawData - is the raw data to encrypt
masterKey - is the symetric encryption key to use for encryption
algorithm - is the algorithm to use, e.g. DES/ECB/NoPadding
provider - is the provider to use, e.g. SunJCE
Returns:
decrypted data
Throws:
javax.crypto.NoSuchPaddingException - if a padding format is incorrect
java.security.NoSuchAlgorithmException - if a particular cryptographic algorithm is requested but is not available in the environment
java.security.InvalidKeyException - for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
javax.crypto.BadPaddingException - if a particular padding mechanism is expected for the input data but the data is not padded properly
java.security.NoSuchProviderException - if a particular security provider is requested but is not available in the environment
javax.crypto.IllegalBlockSizeException - if the length of data provided to a block cipher is incorrect, i.e., does not match the block size of the cipher

encrypt

public static byte[] encrypt(byte[] rawData,
                             javax.crypto.SecretKey masterKey,
                             java.lang.String algorithm)
                      throws javax.crypto.NoSuchPaddingException,
                             java.security.NoSuchAlgorithmException,
                             java.security.InvalidKeyException,
                             javax.crypto.BadPaddingException,
                             java.security.NoSuchProviderException,
                             javax.crypto.IllegalBlockSizeException
This method encrypts the specified data

Parameters:
rawData - is the raw data to encrypt
masterKey - to use for encryption
algorithm - is the algorithm to use, e.g. "DES/ECB/NoPadding"
Returns:
decrypted data
Throws:
javax.crypto.NoSuchPaddingException - if a padding format is incorrect
java.security.NoSuchAlgorithmException - if a a particular cryptographic algorithm is requested but is not available in the environment
java.security.InvalidKeyException - for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
javax.crypto.BadPaddingException - if a particular padding mechanism is expected for the input data but the data is not padded properly
java.security.NoSuchProviderException - if a particular security provider is requested but is not available in the environment
javax.crypto.IllegalBlockSizeException - if the length of data provided to a block cipher is incorrect, i.e., does not match the block size of the cipher

decrypt

public static byte[] decrypt(byte[] encryptedData,
                             javax.crypto.SecretKey masterKey,
                             java.lang.String algorithm,
                             java.lang.String provider)
                      throws javax.crypto.NoSuchPaddingException,
                             java.security.NoSuchAlgorithmException,
                             java.security.InvalidKeyException,
                             javax.crypto.BadPaddingException,
                             java.security.NoSuchProviderException,
                             javax.crypto.IllegalBlockSizeException
This method decrypts the specified data using the specified algorithm.

Parameters:
encryptedData - is the encrypted data
masterKey - to use for decryption
algorithm - is the algorithm to use, e.g. "DES/ECB/NoPadding"
provider - is the provider to use, e.g. SunJCE
Returns:
decrypted data
Throws:
javax.crypto.NoSuchPaddingException - if a padding format is incorrect
java.security.NoSuchAlgorithmException - if a a particular cryptographic algorithm is requested but is not available in the environment
java.security.InvalidKeyException - for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
javax.crypto.BadPaddingException - if a particular padding mechanism is expected for the input data but the data is not padded properly
java.security.NoSuchProviderException - if a particular security provider is requested but is not available in the environment
javax.crypto.IllegalBlockSizeException - if the length of data provided to a block cipher is incorrect, i.e., does not match the block size of the cipher

decrypt

public static byte[] decrypt(byte[] encryptedData,
                             javax.crypto.SecretKey masterKey,
                             java.lang.String algorithm)
                      throws javax.crypto.NoSuchPaddingException,
                             java.security.NoSuchAlgorithmException,
                             java.security.InvalidKeyException,
                             javax.crypto.BadPaddingException,
                             java.security.NoSuchProviderException,
                             javax.crypto.IllegalBlockSizeException
This method decrypts the specified data

Parameters:
encryptedData - is the encrypted data
masterKey - to use for decryption
algorithm - is the algorithm to use, e.g., "DES/ECB/NoPadding"
Returns:
decrypted data
Throws:
javax.crypto.NoSuchPaddingException - if a padding format is incorrect
java.security.NoSuchAlgorithmException - if a a particular cryptographic algorithm is requested but is not available in the environment
java.security.InvalidKeyException - for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
javax.crypto.BadPaddingException - if a particular padding mechanism is expected for the input data but the data is not padded properly
java.security.NoSuchProviderException - if a particular security provider is requested but is not available in the environment
javax.crypto.IllegalBlockSizeException - if the length of data provided to a block cipher is incorrect, i.e., does not match the block size of the cipher

asciiArrayToByteArray

public static byte[] asciiArrayToByteArray(byte[] bytes)
                                    throws java.lang.NumberFormatException
This method converts an array of ascii characters into the actual values that the ascii characters represent. This method is called on a server to convert a block of encrypted data from a client that has been transmitted in ascii text form over HTTP. The real encrypted data can then be decrypted on the server.

Returns:
byte[] actual values.
Throws:
java.lang.NumberFormatException

byteArrayToCharArray

public static byte[] byteArrayToCharArray(byte[] bytes)
This method converts an array of actual values into their ascii character representation. This method is called by a client to convert an encrypted block of data into an ascii representation. The ascii text data can then be transmitted over HTTP to the server.

Returns:
byte[] ascii character representation.


Copyright © 2004 Siebel Systems, Inc. All rights reserved.