• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Encrypt data before storing database

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enter your full question here
<p><b>
i have been experimenting with the JCE package and have been successful in encrypting and decrypting data in a single session.
I have the following question : using JCE, how can I encrypt data with the same key so that it can be decrypted at a later date? I assume that a key can be stored and used to encrypt / decrypt data as needed.
The practical application for this is in the need to store demographic information (possibly financial info) about users in an Oracle database. I would need to encrypt it before storing it and then decrypt it as needed.
my code is
public String decryptpasswd(String username){
String query="select cust_passwd from mxi_customer where cust_uid='"+username+"'";
String s="";
try{
KeyGenerator keygen = KeyGenerator.getInstance("DES");
SecretKey desKey = keygen.generateKey();
Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
// Initialize the cipher for encryption
desCipher.init(Cipher.DECRYPT_MODE, desKey);
// Decrypt the ciphertext
DbBean myDb=new DbBean();
myDb.connect();
ResultSet Rs= myDb.execSQL(query);
if (Rs.next()) {
String passwd=Rs.getString("cust_passwd");
byte[] passwd1=passwd.getBytes();
byte[] cleartext = desCipher.doFinal(passwd1);
s=new String(cleartext);
}
}
catch(Exception e){return e.toString();}return s;
i got Exception
like this
javax.crypto.IllegalBlockSizeException: Input length (with padding) not multiple of 8 bytes
any body know help me
venkat
</b></p>
Please use html tags to format code blocks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic