简体   繁体   English

将Java字节转换为Perl

[英]Converting Java byte to Perl

Have a program written in Java that compresses then encrypts using cipher openssl aes. 有一个用Java编写的程序压缩然后使用密码openssl aes进行加密。

I am writing a program in Perl that will decrypt then uncompress. 我在Perl中编写一个程序,它将解密然后解压缩。

I am having problems with decrypting part and believe it is related to Java byte conversion for IV. 我在解密部分时遇到问题,并且认为它与IV的Java字节转换有关。

Note: I do not know anything about Java language. 注意:我对Java语言一无所知。

Java: Java的:

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

Perl: 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. 我已尝试过上面和其他一些组合,但似乎没有正确的IV。

Please tell me how to do the conversion correctly. 请告诉我如何正确进行转换。

You can read about pack in the docs . 您可以在文档中阅读有关pack的内容。

b corresponds to a bit string in the context of pack , which probably isn't what you want. b对应于pack上下文中的位字符串 ,这可能不是您想要的。 There is an example in perlpacktut that looks like this: perlpacktut中有一个示例如下所示:

$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 . 您可能能够使用对应于signed char(8位)值的 c

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: 我认为这与此Java代码类似:

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));
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM