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); ...
More security: the AES256TextEncryptor util class with a much more secure algorithm: PBEWithHMACSHA512AndAES_256, (you need Java 8 at least to use it):
... AES256TextEncryptor textEncryptor = new AES256TextEncryptor(); 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); ...
More security: the AES256DecimalNumberEncryptor util class with a much more secure algorithm: PBEWithHMACSHA512AndAES_256, (you need Java 8 at least to use it):
... BigInteger myNumber = ...; ... AES256IntegerNumberEncryptor numberEncryptor = new AES256IntegerNumberEncryptor(); numberEncryptor.setPassword(myEncryptionPassword); ... BigInteger myEncryptedNumber = numberEncryptor.encrypt(myNumber); ... BigInteger plainNumber = numberEncryptor.decrypt(myEncryptedNumber); ...
... BasicDecimalNumberEncryptor decimalEncryptor = new BasicDecimalNumberEncryptor(); 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); ...
More security: the AES256DecimalNumberEncryptor util class with a much more secure algorithm: PBEWithHMACSHA512AndAES_256, (you need Java 8 at least to use it):
... BigDecimal myNumber = ...; ... AES256DecimalNumberEncryptor numberEncryptor = new AES256DecimalNumberEncryptor(); numberEncryptor.setPassword(myEncryptionPassword); ... BigDecimal myEncryptedNumber = numberEncryptor.encrypt(myNumber); ... BigDecimal plainNumber = numberEncryptor.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); ... byte[] myEncryptedBinary = binaryEncryptor.encrypt(myBinary); ... String plainBinary = binaryEncryptor.decrypt(myEncryptedBinary); ...
More security: the AES256BinaryEncryptor util class with a much more secure algorithm: PBEWithHMACSHA512AndAES_256, (you need Java 8 at least to use it):
... AES256BinaryEncryptor binaryEncryptor = new AES256BinaryEncryptor(); binaryEncryptor.setPassword(myEncryptionPassword); ... byte[] myEncryptedBytes = binaryEncryptor.encrypt(myBytes); ... byte[] plainBytes = binaryEncryptor.decrypt(myEncryptedBytes); ...