|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bankframe.util.Cryptography
public class 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,
SecretKey masterKey,
String algorithm)
This method decrypts the specified data |
static byte[] |
decrypt(byte[] encryptedData,
SecretKey masterKey,
String algorithm,
String provider)
This method decrypts the specified data using the specified algorithm. |
static byte[] |
encrypt(byte[] rawData,
SecretKey masterKey,
String algorithm)
This method encrypts the specified data |
static byte[] |
encrypt(byte[] rawData,
SecretKey masterKey,
String algorithm,
String provider)
This method encrypts the specified data using the specified algorithm. |
static SecretKey |
generateEncryptionKey(String algorithm,
int keysize)
This method generates a symetric encryption key using the specified algorithm. |
static SecretKey |
generateEncryptionKey(String algorithm,
String provider,
int keysize)
This method generates a symetric encryption key using the specified algorithm and provider. |
static SecretKey |
wrapEncryptionKey(byte[] theEncryptionKey,
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 SecretKey generateEncryptionKey(String algorithm, String provider, int keysize) throws NoSuchProviderException, 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
NoSuchAlgorithmException
- if a particular cryptographic algorithm is requested but is not available in the environment
NoSuchProviderException
- if a particular security provider is requested but is not available in the environmentpublic static SecretKey generateEncryptionKey(String algorithm, int keysize) throws NoSuchProviderException, 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
NoSuchAlgorithmException
- if a particular cryptographic algorithm is requested but is not available in the environment
NoSuchProviderException
public static SecretKey wrapEncryptionKey(byte[] theEncryptionKey, String algorithm) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException
theEncryptionKey
- is the bytes to wrap into a Secret keyalgorithm
- is the algorithm to use, e.g. DES
NoSuchAlgorithmException
- if a particular cryptographic algorithm is requested but is not available in the environment
InvalidKeyException
- for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
InvalidKeySpecException
- for invalid key specifications
NoSuchProviderException
- if a particular security provider is requested but is not available in the environment
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, SecretKey masterKey, String algorithm, String provider) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, NoSuchProviderException, 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
NoSuchPaddingException
- if a padding format is incorrect
NoSuchAlgorithmException
- if a particular cryptographic algorithm is requested but is not available in the environment
InvalidKeyException
- for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
BadPaddingException
- if a particular padding mechanism is expected for the input data but the data is not padded properly
NoSuchProviderException
- if a particular security provider is requested but is not available in the environment
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, SecretKey masterKey, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, NoSuchProviderException, IllegalBlockSizeException
rawData
- is the raw data to encryptmasterKey
- to use for encryptionalgorithm
- is the algorithm to use, e.g. "DES/ECB/NoPadding"
NoSuchPaddingException
- if a padding format is incorrect
NoSuchAlgorithmException
- if a a particular cryptographic algorithm is requested but is not available in the environment
InvalidKeyException
- for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
BadPaddingException
- if a particular padding mechanism is expected for the input data but the data is not padded properly
NoSuchProviderException
- if a particular security provider is requested but is not available in the environment
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, SecretKey masterKey, String algorithm, String provider) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, NoSuchProviderException, 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
NoSuchPaddingException
- if a padding format is incorrect
NoSuchAlgorithmException
- if a a particular cryptographic algorithm is requested but is not available in the environment
InvalidKeyException
- for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
BadPaddingException
- if a particular padding mechanism is expected for the input data but the data is not padded properly
NoSuchProviderException
- if a particular security provider is requested but is not available in the environment
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, SecretKey masterKey, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, NoSuchProviderException, IllegalBlockSizeException
encryptedData
- is the encrypted datamasterKey
- to use for decryptionalgorithm
- is the algorithm to use, e.g., "DES/ECB/NoPadding"
NoSuchPaddingException
- if a padding format is incorrect
NoSuchAlgorithmException
- if a a particular cryptographic algorithm is requested but is not available in the environment
InvalidKeyException
- for invalid Keys (invalid encoding, wrong length, uninitialized, etc)
BadPaddingException
- if a particular padding mechanism is expected for the input data but the data is not padded properly
NoSuchProviderException
- if a particular security provider is requested but is not available in the environment
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 NumberFormatException
bytes
- byte[] ascii characters.
NumberFormatException
public static byte[] byteArrayToCharArray(byte[] bytes)
bytes
- byte[] actual values.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |