Click here to Skip to main content
11,709,120 members (61,502 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Java Encryption
Dear Friends,

I used a KeyGenerator Class for genereate a key.

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...

Leonardo Ayala R.
Posted 11-Jun-13 7:27am
Ron Beyer at 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 at 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.
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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 580
1 Maciej Los 235
2 Peter Leow 219
3 OriginalGriff 214
4 Mika Wendelius 170
0 OriginalGriff 9,348
1 Sergey Alexandrovich Kryukov 8,727
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 11 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100