<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## 12.12 Go 中的密碼學 通過網絡傳輸的數據必須加密,以防止被 hacker(黑客)讀取或篡改,并且保證發出的數據和收到的數據檢驗和一致。 鑒于 Go 母公司的業務,我們毫不驚訝地看到 Go 的標準庫為該領域提供了超過 30 個的包: * `hash`?包:實現了?`adler32`、`crc32`、`crc64`?和?`fnv`?校驗; * `crypto`?包:實現了其它的 hash 算法,比如?`md4`、`md5`、`sha1`?等。以及完整地實現了`aes`、`blowfish`、`rc4`、`rsa`、`xtea`?等加密算法。 下面的示例用?`sha1`?和?`md5`?計算并輸出了一些校驗值。 示例 12.20?[hash_sha1.go](https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/examples/chapter_12/hash_sha1.go): ~~~ // hash_sha1.go package main import ( "fmt" "crypto/sha1" "io" "log" ) func main() { hasher := sha1.New() io.WriteString(hasher, "test") b := []byte{} fmt.Printf("Result: %x\n", hasher.Sum(b)) fmt.Printf("Result: %d\n", hasher.Sum(b)) // hasher.Reset() data := []byte("We shall overcome!") n, err := hasher.Write(data) if n!=len(data) || err!=nil { log.Printf("Hash write error: %v / %v", n, err) } 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`?接口: ~~~ type Hash interface { // Write (via the embedded io.Writer interface) adds more data to the running hash. // It never returns an error. io.Writer // Sum appends the current hash to b and returns the resulting slice. // It does not change the underlying hash state. Sum(b []byte) []byte // Reset resets the Hash to its initial state. Reset() // Size returns the number of bytes Sum will return. Size() int // BlockSize returns the hash's underlying block size. // The Write method must be able to accept any amount // of data, but it may operate more efficiently if all writes // are a multiple of the block size. BlockSize() int } ~~~ 通過 io.WriteString 或 hasher.Write 計算給定字符串的校驗值。 **練習 12.9**:[hash_md5.go](https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/exercises/chapter_12/hash_md5.go): 在示例 12.20 中檢驗 md5 算法。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看