Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

encoding in java and decoding in perl

 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to decode it and then decrypt it, but it's not successful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic