Mysql like AES_ENCRYPTION and AES_DECRYPTION in groovy/Java

In my recent project there was a requirement of encrypting the data in Database but same was needed in the application level as well so at the mysql end i used AES_encryption() and AES_decryption().

e.g.

and in the Groovy/Grails/Java (application end) same can be achieved using the following code :

The main thing to note in the code given above is that for encryption first you need to encrypt data and then apply hex and in case of decryption unhex the data and then decrypt the same.

The main thing to note in the code given above is that for encryption first you need to encrypt data and then apply hex and in case of decryption unhex the data and then decrypt the same.

This helps me hope that helps you guys!!!

Thanks,

Anuj Aneja

Removing/replacing special character from database.

Recently in one of my project i faced a problem that database was having special character, which is shown as space on the User Interface. So as to solve this issue i found a very simple solution which consists of following steps:

1. First, you just need to identify which type special character to be removed/replaced like in my case it was shown as space but stored as <?> in the db.

For that you can use the query e.g.

and you can also refer to this link for ASCII code of character. In my case it was 160.

2. Now, next step is simple just run this query.

Thats it !!!

It helps me a lot!!! Hope that helps you guys!!!

Anuj Aneja