Password Encryption Spring Hibernate Jasypt

Password Encryption Spring Hibernate Jasypt

In my previous tutorial you saw how to encrypt spring or hibernate application password without using any third party API. Today I will show you how to encrypt your application database properties using Jasypt Java library. Jasypt is a java library which provides basic encryption capabilities without putting much effort and of-course coding. As I don’t want to go to the shortcut route and show you only configuration part of Jasypt encryption. To better understand I will create sample Spring Hibernate application to show you how this works.

Tools needed:

  • Eclipse 4.0 or above
  • JDK 1.8
  • Sybase 15.7 (You can use any database)


  • First create table using below script in Sybase database:

  • Insert some dummy data for test:

You can encrypt password using Jasypt utility which you download from here but that will take very long time so I have written custom class to encrypt passoword using StandardPBEStringEncryptor Jaypt API to use it. Please encrypt password using below class:


  • As you see above we are using below:

Password Encryption Spring Hibernate Jasypt

  • Run this class as java application and in my case I got this encrypted password:

Password Encryption Spring Hibernate Jasypt

Important: To use this password just wrap it in the ENC “function” to tell Jasypt to decrypt it while application runs as below:


Now let’s complete project how this works:

  • Create maven project name: SpringHibernatePassEncryptionJasypt and below is final project structure:

Password Encryption Spring Hibernate Jasypt

  • Only important jar to encrypt password with Jasypt is to include below jar dependencies in your pom.xml:

  • pom.xml:

  • spring-context.xml:

  • log4j2.xml:

  • hibernate.querites.xml: For this demo we are not using any query and if you want you can utilize it:

  • hibernate-context.xml:




  • To test the application:

To test this application right click¬† –> Run As –> Java Application and if everything setup correctly you will see below output:

For more information on Jasypt encryption please visit its official site here

download Download Project: SpringHibernatePassEncryptionJasypt

Leave a Reply

Your email address will not be published. Required fields are marked *