Saving and Retrieving encrypted String in Oracle
843810Jul 17 2003 — edited Jul 17 2003Hello,
I have a method that encrypts a string using the PBEWithMD5AndDES method available though the 1.4 JDK. I can pass the encrypted string dirdectly to my decrypt method and it works flawlessly. The problem I'm having is when I try to store the String in an Oracle database and then retrieve it, it won't decrypt.
My guess (pretty sure guess) is that I'm storing the encrypted value either in the wrong column type and/or inserting it incorrectly. Or if I'm inserting it correctly, I am probably retrieveing it the wrong way.
Does anyone have a snipet of code or guidelines to insert an encrypted value into a dB. Your help will be greatly appreciated.
Here's the snipet of code I use to encrypt it:
...
// Initialize PBE Cipher with key and parameters
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
// Decrypt the ciphertext
byte[] encrypt = pbeCipher.doFinal(buffer.getBytes());
// Create a buffer String to be created from the decrypted
encryptedBuffer = new String(encrypt);
...
Then I try to insert encryptBuffer into the DB as a String.