fix(hash):修正Sha256算法中出现的位数设置错误。
This commit is contained in:
parent
185f1f3195
commit
732c01e36c
|
@ -46,8 +46,7 @@ func Sha256_224Hex(data []byte) string {
|
||||||
|
|
||||||
// 根据给定位数计算一个字节数组的Sha256校验和,返回字节数组。
|
// 根据给定位数计算一个字节数组的Sha256校验和,返回字节数组。
|
||||||
func Sum256(data []byte, bitSize ...int) []byte {
|
func Sum256(data []byte, bitSize ...int) []byte {
|
||||||
length := append(bitSize, 256)
|
hasher := hasherSelect(append(bitSize, 256)[0])
|
||||||
hasher := hasherSelect(length[0])
|
|
||||||
hasher.Write(data)
|
hasher.Write(data)
|
||||||
return hasher.Sum(nil)
|
return hasher.Sum(nil)
|
||||||
}
|
}
|
||||||
|
@ -65,7 +64,7 @@ func SumFile256(file string, bitSize ...int) ([]byte, error) {
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
hasher := hasherSelect(bitSize[0])
|
hasher := hasherSelect(append(bitSize, 256)[0])
|
||||||
if _, err := io.Copy(hasher, f); err != nil {
|
if _, err := io.Copy(hasher, f); err != nil {
|
||||||
return nil, fmt.Errorf("未能读取指定文件的内容,%w", err)
|
return nil, fmt.Errorf("未能读取指定文件的内容,%w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user