Class EncryptionUtil
- java.lang.Object
-
- com.norconex.commons.lang.encrypt.EncryptionUtil
-
public class EncryptionUtil extends Object
Simplified encryption and decryption methods using the Advanced Encryption Standard (AES) (since 1.15.0) with a supplied encryption key (which you can also think of as a passphrase, or password).
The "salt" and iteration count used by this class are hard-coded. To use a different encryption or have more control over its creation, you should rely on another implementation or create your own.
To use on the command prompt, use the following command to print usage options:
java -cp norconex-commons-lang-[version].jar com.norconex.commons.lang.encrypt.EncryptionUtil
For example, to use a encryption key store in a file to encrypt some text, add the following arguments to the above command:
<above_command> encrypt -f "/path/to/key.txt" "Encrypt this text"
As of 1.13.0, you can also use the
encrypt.[sh|bat]
anddecrypt.[sh|bat]
files distributed with this library.- Since:
- 1.9.0
- Author:
- Pascal Essiembre
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
decrypt(String encryptedText, EncryptionKey encryptionKey)
Decrypts the given encrypted text with the encryption key supplied.static String
decryptPassword(Credentials credentials)
Decrypts the given credentials password.static String
encrypt(String textToEncrypt, EncryptionKey encryptionKey)
Encrypts the given text with the encryption key supplied.static void
main(String[] args)
-
-
-
Method Detail
-
main
public static void main(String[] args)
-
encrypt
public static String encrypt(String textToEncrypt, EncryptionKey encryptionKey)
Encrypts the given text with the encryption key supplied. If the encryption key is
null
or resolves to blank key, the text to encrypt will be returned unmodified.- Parameters:
textToEncrypt
- text to be encryptedencryptionKey
- encryption key which must resolve to the same value to encrypt and decrypt the supplied text.- Returns:
- encrypted text or
null
iftextToEncrypt
isnull
.
-
decryptPassword
public static String decryptPassword(Credentials credentials)
Decrypts the given credentials password.
- Parameters:
credentials
- credentials from which to decrypt the password- Returns:
- decrypted password.
-
decrypt
public static String decrypt(String encryptedText, EncryptionKey encryptionKey)
Decrypts the given encrypted text with the encryption key supplied.
- Parameters:
encryptedText
- text to be decryptedencryptionKey
- encryption key which must resolve to the same value to encrypt and decrypt the supplied text.- Returns:
- decrypted text or
null
if one ofencryptedText
orkey
isnull
.
-
-