Class EncryptionUtil
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] and
decrypt.[sh|bat] files distributed with this library.
- Since:
- 1.9.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringdecrypt(String encryptedText, EncryptionKey encryptionKey) Decrypts the given encrypted text with the encryption key supplied.static StringdecryptPassword(Credentials credentials) Decrypts the given credentials password.static Stringencrypt(String textToEncrypt, EncryptionKey encryptionKey) Encrypts the given text with the encryption key supplied.static void
-
Method Details
-
main
-
encrypt
Encrypts the given text with the encryption key supplied. If the encryption key is
nullor 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
nulliftextToEncryptisnull.
-
decryptPassword
Decrypts the given credentials password.
- Parameters:
credentials- credentials from which to decrypt the password- Returns:
- decrypted password.
-
decrypt
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
nullif one ofencryptedTextorkeyisnull.
-