我希望能够并行计算加密数据的哈希值,但似乎使用如下的多个编写器,哈希值用明文字节计算。
任何人都知道我如何使用单个副本来实现加密数据并对其进行散列?
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
}
答案 0 :(得分:2)
您需要将io.MultiWriter
移动为cipher.StreamWriter
的作者。这将计算密码文本的哈希值,而不是纯文本:
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
}