Jasypt Users Forum

Problem trying to encrypt hibernate DB password

View: New views
2 Messages — Rating Filter:   Alert me  

Problem trying to encrypt hibernate DB password

by IBeaumont :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hopefully, this will be quick for someone to answer, but I just can't seem to get this working.

I'm using Spring/Hibernate and need to encrypt the hibernate password:

I've added this:
      <bean id="strongEncryptor"
        class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
        <property name="algorithm">
            <value>PBEWithMD5AndTripleDES</value>
        </property>
        <property name="password">
            <value>jasypt</value>
        </property>
      </bean>

      <bean id="hibernateStringEncryptor"
        class="org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor">
            HibernatePBEEncryptorRegistry
        <property name="registeredName">
            <value>stringEncryptor</value>
        </property>
        <property name="encryptor">
            <ref bean="strongEncryptor" />
        </property>
      </bean>

and add these to my hibernate properties
                                <prop key="hibernate.connection.provider_class">org.jasypt.hibernate.connectionprovider.EncryptedPasswordC3P0ConnectionProvider</prop>
                                <prop key="hibernate.connection.encryptor_registered_name">stringEncryptor</prop>                                

but I always get the error:
No string encryptor registered for hibernate with name "stringEncryptor"


I think my problem is that hibernateStringEncryptor should be of type HibernatePBEEncryptorRegistry, but don't understand how I would be able initialise that in Spring.

TIA
Ian

Re: Problem trying to encrypt hibernate DB password

by dfernandez :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

+------------------------+
  Jasypt Users List      
  http://www.jasypt.org 
+------------------------+

Hello,

Initialising your "hibernate string encryptor" this way is though for
using the encryptor for transparent encryption/decryption (from the
jasypt encryption types), not for the encryption of the session factory
passwords.

This is happening to you because the session factory is initialized (and
thus it reads its password and needs the encryptor to be initialized)
*before* the hibernate string encryptor bean is created by Spring.

The safest way to initialize your hibernate string encryptor is to do so
in a ContextListener declared in web.xml.

Regards,
Daniel.


IBeaumont wrote:

> +------------------------+
>   Jasypt Users List      
>   http://www.jasypt.org 
> +------------------------+
>
> Hopefully, this will be quick for someone to answer, but I just can't seem to
> get this working.
>
> I'm using Spring/Hibernate and need to encrypt the hibernate password:
>
> I've added this:
>       <bean id="strongEncryptor"
>         class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
>         <property name="algorithm">
>             <value>PBEWithMD5AndTripleDES</value>
>         </property>
>         <property name="password">
>             <value>jasypt</value>
>         </property>
>       </bean>
>
>       <bean id="hibernateStringEncryptor"
>         class="org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor">
>             HibernatePBEEncryptorRegistry
>         <property name="registeredName">
>             <value>stringEncryptor</value>
>         </property>
>         <property name="encryptor">
>             <ref bean="strongEncryptor" />
>         </property>
>       </bean>
>
> and add these to my hibernate properties
>                                 <prop
> key="hibernate.connection.provider_class">org.jasypt.hibernate.connectionprovider.EncryptedPasswordC3P0ConnectionProvider</prop>
>                                 <prop
> key="hibernate.connection.encryptor_registered_name">stringEncryptor</prop>                                
>
> but I always get the error:
> No string encryptor registered for hibernate with name "stringEncryptor"
>
>
> I think my problem is that hibernateStringEncryptor should be of type
> HibernatePBEEncryptorRegistry, but don't understand how I would be able
> initialise that in Spring.
>
> TIA
> Ian
>  


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
jasypt-users mailing list
jasypt-users@...
https://lists.sourceforge.net/lists/listinfo/jasypt-users
LightInTheBox - Buy quality products at wholesale price