使用多路写入器计算加密数据的哈希值

时间:2016-10-22 08:47:42

标签: go

我希望能够并行计算加密数据的哈希值,但似乎使用如下的多个编写器,哈希值用明文字节计算。

任何人都知道我如何使用单个副本来实现加密数据并对其进行散列?

    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
    }

1 个答案:

答案 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
}