Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Encryption
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 11-Jun-13 8:27am
Comments
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.
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)

  Print Answers RSS
0 Maciej Los 315
1 OriginalGriff 273
2 Aajmot Sk 224
3 Marcin Kozub 210
4 Richard MacCutchan 200
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 11 Jun 2013
Copyright © CodeProject, 1999-2014
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