Question

I am using Java over SQL Server, and have a table with an unencrypted credit card column. How do I encrypt all the fields in the column using AES encryption ?

A SQL or Java (jdbc or hibernate) solution will do.

I want to start using Jasypt to encrypt future values, but I don't know how to encrypt the existing values.

This is the jasypt-spring encryption definition I use:

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

Solution

You may be able to do this directly on the database, depending on what database you use and whether it supports the encryption algorithm you are using.

For example if you are using MySQL and AES, then you can just update with a SQL query;

update credit_card_table set card_number = AES_ENCRYPT(card_number,'password');

It goes without saying that you need to test this first and be sure you're not going to hose your data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top