用多重写入器计算加密数据的哈希

I was hoping to be able to calculate the hash of the encrypted data in parallel, but it seems like using a multiple writer as below, the hash is being calculate with plaintext bytes.

Anyone know how I can use a single copy to achieve both encrypting the data and hashing it?

    writer := &cipher.StreamWriter{S: cipher.NewCTR(block, iv), W: writeFile}
    writeFile.Write(iv)

    if _, err := io.Copy(io.MultiWriter(writer, hash), readFile); err != nil {
        fmt.Println("error during crypto: " + err.Error())
        return "", err
    }

You need to move your io.MultiWriter to be the writer of the cipher.StreamWriter. This will calculate the hash of the cypher text, rather than plain text:

writer := &cipher.StreamWriter{
    S: cipher.NewCTR(block, iv),
    W: io.MultiWriter(writeFile, hash),
}
writeFile.Write(iv)

if _, err := io.Copy(writer, readFile); err != nil {
    fmt.Println("error during crypto: " + err.Error())
    return "", err
}