?
Solved

Converting java base64 to oracle raw value

Posted on 2004-09-07
23
Medium Priority
?
645 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1000 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
 

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 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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