Reputation: 31
Have a program written in Java that compresses then encrypts using cipher openssl aes.
I am writing a program in Perl that will decrypt then uncompress.
I am having problems with decrypting part and believe it is related to Java byte conversion for IV.
Note: I do not 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 have tried above and a few other combinations, but does not seem to be correct IV.
Please tell me how to do the conversion correctly.
Upvotes: 3
Views: 203
Reputation: 5149
You can read about pack
in the docs.
b
corresponds to a bit string in the context of pack
, which probably isn't what you want. There is an example in perlpacktut that 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 corresponds to a 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;
Which 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));
}
}
Upvotes: 3