public class AESCrypto
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
decrypt(java.lang.String encryptedText)
Method that decrypts the specified encrypted string using the key from a file
provided when obtaining reference to
AESCrypto instance using getCryptoInstance(String)
method and removes
any padding added to the encrypted string by the encrypt method. |
java.lang.String |
encrypt(java.lang.String clearText)
Method that encrypts the specified string using the key from a file
provided when obtaining reference to
AESCrypto instance using getCryptoInstance(String)
method. |
static AESCrypto |
getCryptoInstance(java.lang.String keyLocation)
Returns new instance of
AESCrypto. |
static AESCrypto |
getCryptoInstance(java.lang.String keyLocation,
int keySizeInBits)
Returns new instance of
AESCrypto. |
static java.lang.Boolean |
getIsEncrypted() |
static java.lang.String |
getKeyFile()
Constructs and returns the full path to the key file based on the configured
`nchome`, `keyLocation`, and `keyFileName` values.
|
static java.lang.String |
getProviderName() |
static java.lang.String |
getSecurityProviderName()
FIPS (Federal Information Processing Standards) Provider is setting from PrecisionConstants
|
static void |
setIsEncrypted(java.lang.String isEncrypted) |
void |
writeKeyFile(java.lang.String keyFileName)
Instance method that writes a new AES key to the specified file.
|
public static AESCrypto getCryptoInstance(java.lang.String keyLocation) throws java.lang.Exception
AESCrypto. Instances are cached based on
keyLocation parameter, there is always single instance of
AESCrypto class for each value of keyLocation
requested.
If keyLocation exists, the instance will attempt to read a key from it and use it.
If not, it will attempt to create a file of that name and store a random 128-bit key in it.keyLocation - path to a file containing cryptographic keyjava.lang.Exception - if security engine cannot be initialisedpublic static java.lang.Boolean getIsEncrypted()
public static void setIsEncrypted(java.lang.String isEncrypted)
public static AESCrypto getCryptoInstance(java.lang.String keyLocation, int keySizeInBits) throws java.lang.Exception
AESCrypto. Instances are cached based on
keyLocation parameter, there is always single instance of
AESCrypto class for each value of keyLocation
requested.keyLocation - path to a file containing cryptographic keykeySizeInBits - 128, 192 or 256AESCryptojava.lang.Exception - if security engine cannot be initialisedpublic static java.lang.String getSecurityProviderName()
public static java.lang.String getKeyFile()
String, or
null if nchome is null or empty.public static java.lang.String getProviderName()
public java.lang.String encrypt(java.lang.String clearText)
throws java.lang.Exception
AESCrypto instance using getCryptoInstance(String)
method.
The method manually pads to clearText bytes to the expected 16 byte block
size by invoking the padByteArray(byte[], int) method. The decrypt(String) method automatically
unpads the byte-array but be aware that if not using this classes decrypt
method that padding will need to be manually removed.clearText - to be encrypted.java.lang.Exception - if encryption fails.public java.lang.String decrypt(java.lang.String encryptedText)
throws java.lang.Exception
AESCrypto instance using getCryptoInstance(String)
method and removes
any padding added to the encrypted string by the encrypt method.encryptedText - encrypted String to decrypt.java.lang.Exception - if the decryption fails.public void writeKeyFile(java.lang.String keyFileName)
throws java.lang.Exception
keyFileName - full name and path of the file to write.java.lang.Exception - if the file could not be written.