org.jasypt.exceptions.EncryptionOperationNotPossibleException

前端 未结 5 1679
无人共我
无人共我 2021-02-05 18:26

I am using Jasypt-1.9.0 with Spring 3.1 and Hibernate 4.0.1. I have a requirement in my application to connect to database who

5条回答
  •  长发绾君心
    2021-02-05 19:15

    1. Remove all above XML configuration and add the following bean to your configuration class:

      @Bean public DataSource dataSource() {
      DataSourceBuilder dataSourceBuilder = 
      DataSourceBuilder.create();
      dataSourceBuilder.url(dbUrl);
      dataSourceBuilder.username(username);
      dataSourceBuilder.password(password);
      return dataSourceBuilder.build(); 
      }
      
    2. Add values from properties like

      @Value("${db.driverclassname}")
      private String dbDriverClassName;
      
      @Value("${db.url}")
      private String dbUrl;
      
      @Value("${db.username}")
      private String dbUsername;
      
      @Value("${db.password}")
      private String dbPassword;
      

      And pass these values above the data source.

    3. Configure your encryption key in properties file like#

      db.driverclassname=com.mysql.jdbc.Driver
      db.url=jdbc:mysql://localhost:3306/contactsdb
      db.username=contactsuser
      db.password=ENC(XcBjfjDDjxeyFBoaEPhG14wEzc6Ja+Xx
      +hNPrJyQT888=
      
    4. Don't create your encrypted key using cmd and jaspyt jar I will share the link for creating encryption key with your secret key:

      Jasypt Online Encryption and Decryption

    1. Add jaspyat dependency as per your version.

      If you have to run on a server and if you are facing issues like password encryption not matches or not possible, then add one more bean of jdbc template:

      @Bean
      public JdbcTemplate jdbcTemplate(DataSource 
      dataSourcee)
      {
          return new JdbcTemplate(dataSource);
      }
      

    It works fine and no issues found.

    Create the key using that tool. Because I have tried many times using jaspyt command line but the encryption is wrong and it is not supported. You can cross-check key generated using the above tool with the secret key.

提交回复
热议问题