blob: 0173cd7a99a17a91bee797065d998f23642737b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
<h1> Package sha1 </h1> <ul id="short-nav">
<li><code>import "crypto/sha1"</code></li>
<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
<li><a href="#pkg-index" class="indexLink">Index</a></li>
<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
</ul> <h2 id="pkg-overview">Overview </h2> <p>Package sha1 implements the SHA-1 hash algorithm as defined in RFC 3174. </p>
<p>SHA-1 is cryptographically broken and should not be used for secure applications. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
<li><a href="#pkg-constants">Constants</a></li>
<li><a href="#New">func New() hash.Hash</a></li>
<li><a href="#Sum">func Sum(data []byte) [Size]byte</a></li>
</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_New">New</a></dd> <dd><a class="exampleLink" href="#example_New_file">New (File)</a></dd> <dd><a class="exampleLink" href="#example_Sum">Sum</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>sha1.go</span> <span>sha1block.go</span> <span>sha1block_amd64.go</span> </p> <h2 id="pkg-constants">Constants</h2> <p>The blocksize of SHA-1 in bytes. </p>
<pre data-language="go">const BlockSize = 64</pre> <p>The size of a SHA-1 checksum in bytes. </p>
<pre data-language="go">const Size = 20</pre> <h2 id="New">func <span>New</span> </h2> <pre data-language="go">func New() hash.Hash</pre> <p>New returns a new hash.Hash computing the SHA1 checksum. The Hash also implements <span>encoding.BinaryMarshaler</span> and <span>encoding.BinaryUnmarshaler</span> to marshal and unmarshal the internal state of the hash. </p> <h4 id="example_New"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">h := sha1.New()
io.WriteString(h, "His money is twice tainted:")
io.WriteString(h, " 'taint yours and 'taint mine.")
fmt.Printf("% x", h.Sum(nil))
</pre> <p>Output:</p> <pre class="output" data-language="go">59 7f 6a 54 00 10 f9 4c 15 d7 18 06 a9 9a 2c 87 10 e7 47 bd
</pre> <h4 id="example_New_file"> <span class="text">Example (File)</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">
f, err := os.Open("file.txt")
if err != nil {
log.Fatal(err)
}
defer f.Close()
h := sha1.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
fmt.Printf("% x", h.Sum(nil))
</pre> <h2 id="Sum">func <span>Sum</span> <span title="Added in Go 1.2">1.2</span> </h2> <pre data-language="go">func Sum(data []byte) [Size]byte</pre> <p>Sum returns the SHA-1 checksum of the data. </p> <h4 id="example_Sum"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">data := []byte("This page intentionally left blank.")
fmt.Printf("% x", sha1.Sum(data))
</pre> <p>Output:</p> <pre class="output" data-language="go">af 06 49 23 bb f2 30 15 96 aa c4 c2 73 ba 32 17 8e bc 4a 96
</pre><div class="_attribution">
<p class="_attribution-p">
© Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
<a href="http://golang.org/pkg/crypto/sha1/" class="_attribution-link">http://golang.org/pkg/crypto/sha1/</a>
</p>
</div>
|