Solved

Converting java base64 to oracle raw value

Posted on 2004-09-07
23
627 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 54
ejb example issues 3 25
collection output issue 9 36
What browser will run Java? 7 55
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 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