Jasypt + Hibernate3 integration + decrypt

View: Old framed views
5 Messages — Rating Filter:   Alert me  
jmirmon
Jasypt + Hibernate3 integration + decrypt
Reply More
Rate this Message:
Print
Show in thread view
Show in list view (by date)
Permalink
Hi!

I would like to encrypt some attributes of an entity in a transparent way when I persist it into database using Hibernate. I've followed the guide: http://www.jasypt.org/hibernate3.html and it works like a charm.

The problem is that when I want to get back the entity from database I would like to get the entity with all attributes decryted. I don't know if I am missing something important but I get the attributes encrypted.

I've followed all the steps of the guide. Any ideas?.

Thanks in advance.
jmirmon
Re: Jasypt + Hibernate3 integration + decrypt
Reply More
Rate this Message:
Print
Show in thread view
Show in list view (by date)
Permalink
Solved.

Everything works well doing some executions, I initialize Spring container (is a web app) 5 or 6 times and then...

Caused by: org.jasypt.exceptions.EncryptionInitializationException: No string encryptor registered for hibernate with name "strongHibernateStringEncryptor"
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.checkInitialization(AbstractEncryptedAsStringType.java:250)
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.nullSafeGet(AbstractEncryptedAsStringType.java:142)
        at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
        at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)

Any ideas?.

jmiranda wrote:
Hi!

I would like to encrypt some attributes of an entity in a transparent way when I persist it into database using Hibernate. I've followed the guide: http://www.jasypt.org/hibernate3.html and it works like a charm.

The problem is that when I want to get back the entity from database I would like to get the entity with all attributes decryted. I don't know if I am missing something important but I get the attributes encrypted.

I've followed all the steps of the guide. Any ideas?.

Thanks in advance.
bornleo
Re: Jasypt + Hibernate3 integration + decrypt
Reply More
Rate this Message:
Print
Show in thread view
Show in list view (by date)
Permalink
You need to make an entry of strongHibernateStringEncryptor in your spring context i.e. applicationConext.xml in my case.

Something like this.

<bean id="strongHibernateStringEncryptor"
            class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
            <property name="algorithm">
                <value>PBEWithMD5AndTripleDES</value>
            </property>
            <property name="password">
                <value>jasypt</value>
            </property>
        </bean>

Hope this helps.

Leo.


Solved.

Everything works well doing some executions, I initialize Spring container (is a web app) 5 or 6 times and then...

Caused by: org.jasypt.exceptions.EncryptionInitializationException: No string encryptor registered for hibernate with name "strongHibernateStringEncryptor"
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.checkInitialization(AbstractEncryptedAsStringType.java:250)
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.nullSafeGet(AbstractEncryptedAsStringType.java:142)
        at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
        at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)

Any ideas?.

jmiranda wrote:
Hi!

I would like to encrypt some attributes of an entity in a transparent way when I persist it into database using Hibernate. I've followed the guide: http://www.jasypt.org/hibernate3.html and it works like a charm.

The problem is that when I want to get back the entity from database I would like to get the entity with all attributes decryted. I don't know if I am missing something important but I get the attributes encrypted.

I've followed all the steps of the guide. Any ideas?.

Thanks in advance.

jmirmon
Re: Jasypt + Hibernate3 integration + decrypt
Reply More
Rate this Message:
Print
Show in thread view
Show in list view (by date)
Permalink
Hi Leo, yes I had this piece of configuration.  Maybe I was missing something. At the end I've created a spring bean and inside I've used jasypt to encrypt/decrypt, then I have to get the bean and call decrypt/encrypt everytime I want to get/update my entity but doesn't matter, is just in one time and it does not supose a big headchache :)

Thanks for your help.



You need to make an entry of strongHibernateStringEncryptor in your spring context i.e. applicationConext.xml in my case.

Something like this.

<bean id="strongHibernateStringEncryptor"
            class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
            <property name="algorithm">
                <value>PBEWithMD5AndTripleDES</value>
            </property>
            <property name="password">
                <value>jasypt</value>
            </property>
        </bean>

Hope this helps.

Leo.

jmiranda wrote:
Solved.

Everything works well doing some executions, I initialize Spring container (is a web app) 5 or 6 times and then...

Caused by: org.jasypt.exceptions.EncryptionInitializationException: No string encryptor registered for hibernate with name "strongHibernateStringEncryptor"
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.checkInitialization(AbstractEncryptedAsStringType.java:250)
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.nullSafeGet(AbstractEncryptedAsStringType.java:142)
        at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
        at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)

Any ideas?.

jmiranda wrote:
Hi!

I would like to encrypt some attributes of an entity in a transparent way when I persist it into database using Hibernate. I've followed the guide: http://www.jasypt.org/hibernate3.html and it works like a charm.

The problem is that when I want to get back the entity from database I would like to get the entity with all attributes decryted. I don't know if I am missing something important but I get the attributes encrypted.

I've followed all the steps of the guide. Any ideas?.

Thanks in advance.
Allan Lang
Re: Jasypt + Hibernate3 integration + decrypt
Reply More
Rate this Message:
Print
Show in thread view
Show in list view (by date)
Permalink
I've also recently hit the "No string encryptor registered for hibernate..." error and I'm also using Spring. The solution I found to the intermittent initialisation problem was to make my data access components dependent on the strongHibernateStringEncryptor bean, thereby ensuring that bean was always present in the application context before any of my data access components might start to try doing anything requiring en/decryption. I think I hit the problem because another of the beans in my Spring definition performed some data access as part of the execution of its init-method, and I guess there is no guarantee that this is called after all other beans have been instantiated.

So anyway, long explanation, but simple solution. Try adding something like this, shown here on another bean which forms part of my data access infrastructure:

        <bean id="transactionManager"
                class="org.springframework.orm.hibernate3.HibernateTransactionManager"
                depends-on="hibernateStringEncryptor">
                <property name="sessionFactory" ref="sessionFactory" />
                ...
        </bean>

        <bean id="hibernateStringEncryptor" class="org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor">
                <property name="registeredName" value="strongHibernateStringEncryptor"/>
                <property name="password" value="..." />
        </bean>

Hope that helps.

Allan



You need to make an entry of strongHibernateStringEncryptor in your spring context i.e. applicationConext.xml in my case.

Something like this.

<bean id="strongHibernateStringEncryptor"
            class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
            <property name="algorithm">
                <value>PBEWithMD5AndTripleDES</value>
            </property>
            <property name="password">
                <value>jasypt</value>
            </property>
        </bean>

Hope this helps.

Leo.

jmiranda wrote:
Solved.

Everything works well doing some executions, I initialize Spring container (is a web app) 5 or 6 times and then...

Caused by: org.jasypt.exceptions.EncryptionInitializationException: No string encryptor registered for hibernate with name "strongHibernateStringEncryptor"
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.checkInitialization(AbstractEncryptedAsStringType.java:250)
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.nullSafeGet(AbstractEncryptedAsStringType.java:142)
        at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
        at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)

Any ideas?.

jmiranda wrote:
Hi!

I would like to encrypt some attributes of an entity in a transparent way when I persist it into database using Hibernate. I've followed the guide: http://www.jasypt.org/hibernate3.html and it works like a charm.

The problem is that when I want to get back the entity from database I would like to get the entity with all attributes decryted. I don't know if I am missing something important but I get the attributes encrypted.

I've followed all the steps of the guide. Any ideas?.

Thanks in advance.