title: Migrate Java decryption code to Golang
body: <p>I'm struggling with the migration of Java code to Golang for the last few days and I am now stuck. This is the working Java code:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>My implementation in Golang:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>What I know so far:</p>
  
  <ul>
  <li>all error values omitted by <code>_</code> are <code>nil</code> in this piece of code</li>
  <li>the bzip2 header ("BZ") must be omitted for <code>CBzip2InputStream</code>, but not for <code>bzip2.NewReader</code></li>
  <li>the first 16 bytes read from <code>instream</code> in Java and golang are the same, starting with the 17th byte all bytes differ for whatever reason</li>
  </ul>