Click here to Skip to main content
13,056,352 members (120,123 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 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.
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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170728.5 | Last Updated 11 Jun 2013
Copyright © CodeProject, 1999-2017
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