Solved

Converting java base64 to oracle raw value

Posted on 2004-09-07
23
623 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 73
Java - Why doesn't this JFrame work 3 45
Arrays.asList  VS  ArrayList 4 45
Way to decrease size of apk file 9 46
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

863 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

21 Experts available now in Live!

Get 1:1 Help Now