The easiest way to use Jasypt is using its easy encryption tools, which are called the utils, because they live in the org.jasypt.util package.
They are called utils because they are ready-to-use, preconfigured digesters and encryptors you can use without knowing much about their configuration.
These utils are categorised depending on the task they are intended to do:
(Note that, generally, when we talk about "password encryption", we are in fact talking about "password digesting", which is the technically correct term)
...
Digester digester = new Digester();
digester.setAlgorithm("SHA-1");
...
byte[] digest = digester.digest(message);
...
All classes here implement the org.jasypt.util.password.PasswordEncryptor interface, so that they can be used interchangeabily if needed.
...
BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
String encryptedPassword = passwordEncryptor.encryptPassword(userPassword);
...
if (passwordEncryptor.checkPassword(inputPassword, encryptedPassword)) {
// correct!
} else {
// bad login!
}
...
...
StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();
String encryptedPassword = passwordEncryptor.encryptPassword(userPassword);
...
if (passwordEncryptor.checkPassword(inputPassword, encryptedPassword)) {
// correct!
} else {
// bad login!
}
...
...
ConfigurablePasswordEncryptor passwordEncryptor = new ConfigurablePasswordEncryptor();
passwordEncryptor.setAlgorithm("SHA-1");
passwordEncryptor.setPlainDigest(true);
String encryptedPassword = passwordEncryptor.encryptPassword(userPassword);
...
if (passwordEncryptor.checkPassword(inputPassword, encryptedPassword)) {
// correct!
} else {
// bad login!
}
...
All classes here implement the org.jasypt.util.text.TextEncryptor interface, so that they can be used interchangeabily if needed.
... BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); textEncryptor.setPassword(myEncryptionPassword); ... String myEncryptedText = textEncryptor.encrypt(myText); ... String plainText = textEncryptor.decrypt(myEncryptedText); ...
... StrongTextEncryptor textEncryptor = new StrongTextEncryptor(); textEncryptor.setPassword(myEncryptionPassword); ... String myEncryptedText = textEncryptor.encrypt(myText); ... String plainText = textEncryptor.decrypt(myEncryptedText); ...
All classes here implement either the org.jasypt.util.numeric.DecimalNumberEncryptor or the org.jasypt.util.numeric.IntegerNumberEncryptor interfaces, so that they can be used interchangeabily if needed.
... BasicIntegerNumberEncryptor integerEncryptor = new BasicIntegerNumberEncryptor(); integerEncryptor.setPassword(myEncryptionPassword); ... BigInteger myEncryptedNumber = textEncryptor.encrypt(myNumber); ... BigInteger plainNumber = textEncryptor.decrypt(myEncryptedNumber); ...
... StrongIntegerNumberEncryptor integerEncryptor = new StrongIntegerNumberEncryptor(); integerEncryptor.setPassword(myEncryptionPassword); ... BigInteger myEncryptedNumber = integerEncryptor.encrypt(myNumber); ... BigInteger plainNumber = integerEncryptor.decrypt(myEncryptedNumber); ...
... BasicIntegerNumberEncryptor decimalEncryptor = new BasicIntegerNumberEncryptor(); decimalEncryptor.setPassword(myEncryptionPassword); ... BigDecimal myEncryptedNumber = decimalEncryptor.encrypt(myNumber); ... BigDecimal plainNumber = decimalEncryptor.decrypt(myEncryptedNumber); ...
... StrongDecimalNumberEncryptor decimalEncryptor = new StrongDecimalNumberEncryptor(); decimalEncryptor.setPassword(myEncryptionPassword); ... BigDecimal myEncryptedNumber = decimalEncryptor.encrypt(myNumber); ... BigDecimal plainNumber = decimalEncryptor.decrypt(myEncryptedNumber); ...
All classes here implement the org.jasypt.util.binary.BinaryEncryptor interface, so that they can be used interchangeabily if needed.
... BasicBinaryEncryptor binaryEncryptor = new BasicBinaryEncryptor(); binaryEncryptor.setPassword(myEncryptionPassword); ... byte[] myEncryptedBinary = binaryEncryptor.encrypt(myBinary); ... String plainBinary = binaryEncryptor.decrypt(myEncryptedBinary); ...
... StrongBinaryEncryptor binaryEncryptor = new StrongBinaryEncryptor(); binaryEncryptor.setPassword(myEncryptionPassword); ... String myEncryptedBinary = binaryEncryptor.encrypt(myBinary); ... String plainBinary = binaryEncryptor.decrypt(myEncryptedBinary); ...