Convert Java bytes to Perl

You have a program written in Java that compresses and encrypts with openssl aes encryption.

I am writing a program in Perl that decrypts and then unpacks.

I am having trouble decrypting part and believe it has to do with converting Java byte to IV.

Note. I don't know anything about Java language.

Java:

static byte[] IV = new byte[] {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

      

Perl:

my $iv = pack('b128', 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);

      

I've tried the above and several other combinations but doesn't seem to be the right one.

Please tell me how to do the conversion correctly.

+3


source to share


1 answer


You can read about pack

in the docs .

b

matches a bit string in context pack

, which is probably not what you want. An example in perlpacktut looks like this:

$byte = pack( 'B8', '10001100' ); # start with MSB
$byte = pack( 'b8', '00110001' ); # start with LSB

      

You might be able to use c

which matches the signed char (8-bit) value .



my $iv = pack('c16', 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
print unpack 'c16', $iv;

      

What I think would be similar to this Java code:

import java.lang.Byte;
import java.util.Arrays;
public class ByteStuff{

     public static void main(String []args){

        byte[] IV = new byte[] {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
         System.out.println(Arrays.toString(IV));
     }
}

      

+3


source







All Articles