6/28/11

There are many problems when you try encrypting a string such password, credit card nos, phone no. etc ie1. which algorithm to use.2. how to store the generated Key in the database.3. should i use MD5, AES etc.Here is the question to all your answers. After spending sometime on this i finally got the best algorithm that a person can use to encrypt and decrypt data while he/she also wants to store those encrypted strings and later on want to decrypt it while retrieving the data.Many people face problem while decrypting the encrypted data as the KEY used for encryption if stored as String in database then it becomes very tough to use that string as the KEY. So below is the code where you only need to store the encrypted code and not the key. The decryption will take place as an when wanted.For encryption we must use a secret key along with an algorithm. In the following example we use an algorithm called AES 128 and the bytes of the word "TheBestSecretKey" as the secret key (the best secret key we found in this world). AES algorithm can use a key of 128 bits (16 bytes * 8); so we selected that key.

Small improvement to the code is to change the usage of sun.misc.BASE64 to Apache Commons Codec which provides Base64 http://commons.apache.org/codec/api-release/org/apache/commons/codec/binary/Base64.html

You should be using java.sun.misc.base64 even in Java 6, because it's not part of the API of java.For more info: http://java.sun.com/products/jdk/faq/faq-sun-packages.html

You have really save me from a very big challenge that gave me sleepless nite.I was just looking for something like this to know my way forward and all i could get from Stackoverflow was the first class AESencrp but how to checkout was another brain dump.

hello sir iam srikanth. iam doing project on encryption algorithm which can be implemented in a sensor platform. can we do this? is this feasible? can u help me out. please help me at srikanthmadireddy44@gmail.com