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]
and
decrypt.[sh|bat]
files distributed with this library.
Modifier and Type | Method and 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) |
public static void main(String[] args)
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.
textToEncrypt
- text to be encryptedencryptionKey
- encryption key which must resolve to the same
value to encrypt and decrypt the supplied text.null
if
textToEncrypt
is null
.public static String decryptPassword(Credentials credentials)
Decrypts the given credentials password.
credentials
- credentials from which to decrypt the passwordpublic static String decrypt(String encryptedText, EncryptionKey encryptionKey)
Decrypts the given encrypted text with the encryption key supplied.
encryptedText
- text to be decryptedencryptionKey
- encryption key which must resolve to the same
value to encrypt and decrypt the supplied text.null
if one of
encryptedText
or key
is null
.Copyright © 2008–2023 Norconex Inc.. All rights reserved.