Solved

Converting java base64 to oracle raw value

Posted on 2004-09-07
23
618 Views
Last Modified: 2012-05-05
We have a encrypted byte array which has been encrypted using des3, we have converted this to  base 64 string

We now want to decrypt this string in oracle.
To do this we use the oracle 9i functions
we convert base64 string to a raw value, then we decode the raw value and then we decrypt the raw value in oracle 9i using des3.

We are not getting the same value?  Any ideas what we are doing wrong?

The main thing is we are having problems trying to convert data between oracle and java.
In oracle the encrypted value is stored as a raw value in a oracle database.
We want to be able to encrypt the data in java in a way that the data can be stored in this raw field.

To do this we encrypt the data in java using des3, this returns a byte array, we convert this to a base64 encoded string so we can write this to a file.
We then read this value in oracle.

0
Comment
Question by:inzaghi
  • 11
  • 6
  • 6
23 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11994957
can u post how you do the conversion
though base64 seems unnecesary and just complicates the situation.

0
 
LVL 92

Expert Comment

by:objects
ID: 11994972
which conversion is giving the wrong result, the base64 or the decryption?
0
 

Author Comment

by:inzaghi
ID: 11995087
String base64 = new Base64Encoder(b).processString();
where b is the encrypted des3 byte array.

I need to write the data to the a file so I encoded it has a base 64 string.
ie has before

username+fileseperator+encryptedbase64string

Oracle stores the encrypted data has a raw value so it needs to do the necesary conversions.  

At the moment I don't think we may not be using the same mode and padding.
In java I have specified no padding and mode so it uses /ECB/PKCS5Padding.

I need to check what mode and padding is used in oracle.

Thanks for the help


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11995109
Can you confirm that the base64 parts en/decode to the same value?
0
 
LVL 92

Expert Comment

by:objects
ID: 11995129
> I need to write the data to the a file so I encoded it has a base 64 string.

as i explained to you before thats unnecessary, you can write the encode bytes directly.
0
 
LVL 92

Expert Comment

by:objects
ID: 11995134
you need to compare the data at each step to determine which state is causing the error.
0
 

Author Comment

by:inzaghi
ID: 11995498
I think the main problem is with the mode and padding is different in both
platforms

In java I am encrypting with
the following

Algorithm: DESede
mode : ECB
padding: PKCS5Padding

How do I set this in oracle?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11995536
Why do you have to en/decode in both Java *and* Oracle?
0
 

Author Comment

by:inzaghi
ID: 11995557
Just have to, main thing is to encrypt in java and decrypt in oracle
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 11995559
> How do I set this in oracle?

You just need to store the bytes in Oracle, it does not need to worry about encrypting/decrypting it.
Thats the job of the clienbt accessing the data.

0
 
LVL 92

Expert Comment

by:objects
ID: 11995596
Check that you're using the correct character encoding whenever switching between strings and bytes.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 92

Expert Comment

by:objects
ID: 11995648
0
 

Author Comment

by:inzaghi
ID: 11996367
Ok, des3 encrypts data in java and returns a byte array.

If we now want to decrypt this data in oracle.  Des3 in oracle expects a raw value
what form should we store this data in java so we can decrypt in oracle.
0
 
LVL 92

Expert Comment

by:objects
ID: 11996414
byte array
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 11996420
>>what form should we store this data in java

How do you mean - java doesn't store anything, other than in class files?
0
 
LVL 92

Expert Comment

by:objects
ID: 11996449
and if using strings make sure you use the same encoding when going back and forth.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11996485
As far as i can remember fromyour earlier qs, you are storing the encrypted data in files too (not sure why). You could store a byte array in those files, but since you want to store other info along with the encrypted bytes, you will have to do one of two things:

a. use a text file
b. use fixed width fields

or you won't be able to delimit the encrypted bytes from your other info
0
 

Author Comment

by:inzaghi
ID: 11996680
cant I convert the enrypted byte array to a string using
new String(encryptedbyteArray, "UTF-8)
0
 

Author Comment

by:inzaghi
ID: 11998097
How do I convert a raw value from oracle into a byte array in java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11998155
>>cant I convert the enrypted byte array to a string using ...

No. Why should an arbitrary array of bytes make sense as a String?

>>How do I convert a raw value from oracle into a byte array in java

byte[] encryptedBytes = resultSet.getBytes(cryptCol);
0
 
LVL 92

Expert Comment

by:objects
ID: 12001046
> How do I convert a raw value from oracle into a byte array in java

No conversion should be necessary. You should be reading it as a byte array from the db.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12028951
8-)
0
 
LVL 92

Expert Comment

by:objects
ID: 12031874
Thanks mate :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now