Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I used a KeyGenerator Class for genereate a key.
example:

Key clave = keyGen.generateKey(); //(another code lines are not specify here...)


and a Cipher Class too, you can see:

Cipher cifrar = Cipher.getInstance("DES/ECB/PKCS5Padding");



Finally I encripted my string like this:


String myPass="leo2013";
byte[] myPass2= myPass.getBytes("UTF8");
cifrar.init(Cipher.ENCRYPT_MODE, clave);
        byte[] cipherText = cifrar.doFinal(mPass2);


I need to SAVE the CLAVE object in a Data Base because I need to decrypt in ahoter Class myPass.


Please anyone know that how I can save the Clave Object to a database and
recover myPass???


Thanks in advance...

Att:
Leonardo Ayala R.
Posted
Comments
Ron Beyer 11-Jun-13 14:01pm    
Its really bad form to have two way encryption, especially if you are storing your keys in the database for decryption. This opens you up to giving away all your data if somebody is able to run a simple SQL statement on your database. I would choose a one-way encryption, store the encrypted value in your database, and when logging in, compare the encrypted value to the stored value. If the user forgets their password (another security leak), just reset it then email them the information.
Shubhashish_Mandal 12-Jun-13 2:29am    
I guess you want to save the java object into database. If yes, then here is some example to do that.
http://javapapers.com/core-java/serialize-de-serialize-java-object-from-database/
And also keep in mind what "Ron" want to say.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900