mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-11-13 09:16:10 +08:00
12.7-12.12
This commit is contained in:
@@ -37,12 +37,14 @@ func main() {
|
||||
checksum := hasher.Sum(b)
|
||||
fmt.Printf("Result: %x\n", checksum)
|
||||
}
|
||||
/* Output:
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
Result: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
Result: [169 74 143 229 204 177 155 166 28 76 8 115 211 145 233 135 152 47 187 211]
|
||||
Result: e2222bfc59850bbb00a722e764a555603bb59b2a
|
||||
*/
|
||||
|
||||
```
|
||||
|
||||
通过调用 `sha1.New()` 创建了一个新的 `hash.Hash` 对象,用来计算 SHA1 校验值。`Hash` 类型实际上是一个接口,它实现了 `io.Writer` 接口:
|
||||
@@ -69,7 +71,6 @@ type Hash interface {
|
||||
// are a multiple of the block size.
|
||||
BlockSize() int
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
通过 io.WriteString 或 hasher.Write 计算给定字符串的校验值。
|
||||
@@ -78,7 +79,6 @@ type Hash interface {
|
||||
|
||||
在示例 12.20 中检验 md5 算法。
|
||||
|
||||
|
||||
## 链接
|
||||
|
||||
- [目录](directory.md)
|
||||
|
||||
Reference in New Issue
Block a user