• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris

Encrypt data before storing database

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
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="";
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();
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
Please use html tags to format code blocks.
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Low Tech Laboratory
    Bookmark Topic Watch Topic
  • New Topic