|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.bankframe.util.Cryptography
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 |
public Cryptography()
Method Detail |
public static javax.crypto.SecretKey generateEncryptionKey(java.lang.String algorithm, java.lang.String provider, int keysize) throws java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException
algorithm
- is the name of the Encryption algorithm, e.g. DESprovider
- is the name of the provider to use, e.g. SunJCEkeysize
- is an algorithm-specific metric, specified in number of bits. e.g. 56 for Des encryption key
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 environmentpublic static javax.crypto.SecretKey generateEncryptionKey(java.lang.String algorithm, int keysize) throws java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException
algorithm
- is the name of the Encryption algorithm, e.g. DESkeysize
- is an algorithm-specific metric, specified in number of bits. e.g. 56 for Des encryption key
java.security.NoSuchAlgorithmException
- if a particular cryptographic algorithm is requested but is not available in the environment
java.security.NoSuchProviderException
public static javax.crypto.SecretKey wrapEncryptionKey(byte[] theEncryptionKey, java.lang.String algorithm) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException
theEncryptionKey
- is the bytes to wrap into a Secret keyalgorithm
- is the algorithm to use, e.g. DES
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 cipherpublic 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
rawData
- is the raw data to encryptmasterKey
- is the symetric encryption key to use for encryptionalgorithm
- is the algorithm to use, e.g. DES/ECB/NoPaddingprovider
- is the provider to use, e.g. SunJCE
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 cipherpublic 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
rawData
- is the raw data to encryptmasterKey
- to use for encryptionalgorithm
- is the algorithm to use, e.g. "DES/ECB/NoPadding"
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 cipherpublic 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
encryptedData
- is the encrypted datamasterKey
- to use for decryptionalgorithm
- is the algorithm to use, e.g. "DES/ECB/NoPadding"provider
- is the provider to use, e.g. SunJCE
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 cipherpublic 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
encryptedData
- is the encrypted datamasterKey
- to use for decryptionalgorithm
- is the algorithm to use, e.g., "DES/ECB/NoPadding"
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 cipherpublic static byte[] asciiArrayToByteArray(byte[] bytes) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static byte[] byteArrayToCharArray(byte[] bytes)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |