wood burning stoves 2.0*
The moose likes Perl and the fly likes encoding in java and decoding in perl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Languages » Perl
Bookmark "encoding in java and decoding in perl" Watch "encoding in java and decoding in perl" New topic
Author

encoding in java and decoding in perl

reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
Hi, I'm running into problem when I'm trying to use AES to encrypt and encode some string and send to another server where there is perl program running which will decode and decrypt it.

I used base 64 encoding in Java and decode it in perl. But it looks like the string get coded does not match between java and perl. How should I solve this problem?

Plus, even after encoding/decoding is working, will perl recognize java's byte array as encrypted value?

Thanks.


SCJA, SCJP5.0, SCBCD, SCWCD
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There's no "recognition": the server side will either work or not--as long as the data coming in matches whatever format the Perl code is expecting.

As to what your actual problem is--AES is AES, regardless of the platform. Without knowing anything more about how the encryption/decryption is happening, how you're sending the data, etc. it's really difficult to help.
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
here is my code in java:



here is the code in perl:


where I hardcoded value for $a_str, which is generated from java. But $de_base64 prints out some corrupted characters....
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You've left out some important information, but okay.

Is the value of $a_str in your Perl the value of the Base64-encoded, AES-encrypted output from the Java code?
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
David Newton wrote:You've left out some important information, but okay.

Is the value of $a_str in your Perl the value of the Base64-encoded, AES-encrypted output from the Java code?


yes, it is. It's the value from that java method.
That Base64 class is imported from com.sun.org.apache.xerces.internal.impl.dv.util.Base64;


Here is the code I continue with the hardcoded value:


The last line of code causes an error: Ciphertext does not begin with a valid header for 'salt' header mode at ./aes.pl line 26

Is there any setting I did wrong for AES between java and perl?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And when you AES decode the Base64-decoded string, *that's* when you see you're not getting the original string?
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
I'm trying to decode it and then decrypt it, but it's not successful.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: encoding in java and decoding in perl