過去数日間、JavaコードのGolangへの移行に苦労していて、今は行き詰まっています。これは動作するJavaコードです。
final Key k = new SecretKeySpec(keyString.getBytes(), "AES");
Cipher c = Cipher.getInstance("AES");
c.init(Cipher.DECRYPT_MODE, k);
final InputStream in = new BufferedInputStream(new FileInputStream(fileNameToDecrypt));
final CipherInputStream instream = new CipherInputStream(in, c);
if (instream.read() != 'B') {
System.out.println("Error");
}
if (instream.read() != 'Z') {
System.out.println("Error");
}
final CBZip2InputStream zip = new CBZip2InputStream(instream);
Golangでの私の実装:
c, _ := aes.NewCipher([]byte(keyString))
// IV must be defined in golang
iv := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
d := cipher.NewCBCDecrypter(c, iv)
fi, _ := os.Open(fileNameToDecrypt)
stat, _ := fi.Stat()
enc := make([]byte, stat.Size())
dec := make([]byte, stat.Size())
fi.Read(enc)
d.CryptBlocks(dec, enc)
instream := bytes.NewBuffer(dec)
zip := bzip2.NewReader(instream)
私がこれまでに知っていること:
- で省略されたすべてのエラー値
_
はnil
、このコードに含まれています - bzip2ヘッダー( "BZ")は、の場合は省略できますが
CBzip2InputStream
、の場合は省略できません。bzip2.NewReader
- Javaとgolangで読み取られた最初の16バイト
instream
は同じで、17バイト目からは、何らかの理由ですべてのバイトが異なります。