sha1
This commit is contained in:
parent
908f8dc36e
commit
30ac0047a3
@ -53,7 +53,7 @@ Epoch
|
|||||||
Случайные числа (Random Numbers)
|
Случайные числа (Random Numbers)
|
||||||
Парсинг чисел (Number Parsing)
|
Парсинг чисел (Number Parsing)
|
||||||
Парсинг URL (URL Parsing)
|
Парсинг URL (URL Parsing)
|
||||||
SHA1 Hashes
|
Хеш SHA1 (SHA1 Hashes)
|
||||||
Base64 Encoding
|
Base64 Encoding
|
||||||
Reading Files
|
Reading Files
|
||||||
Writing Files
|
Writing Files
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
// [_SHA1 hashes_](http://en.wikipedia.org/wiki/SHA-1) are
|
// [_Хеши SHA1_](http://en.wikipedia.org/wiki/SHA-1) часто
|
||||||
// frequently used to compute short identities for binary
|
// используются для вычисления коротких идентификаторов
|
||||||
// or text blobs. For example, the [git revision control
|
// для двоичных или текстовых BLOB-объектов. Например,
|
||||||
// system](http://git-scm.com/) uses SHA1s extensively to
|
// [система контроля версий git](http://git-scm.com/) широко использует SHA1 для
|
||||||
// identify versioned files and directories. Here's how to
|
// идентификации версионных файлов и каталогов. Вот как
|
||||||
// compute SHA1 hashes in Go.
|
// вычислить хэши SHA1 в Go.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// Go implements several hash functions in various
|
// Go реализует несколько хеш-функций в пакете
|
||||||
// `crypto/*` packages.
|
// `crypto/*`.
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -17,23 +17,24 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
s := "sha1 this string"
|
s := "sha1 this string"
|
||||||
|
|
||||||
// The pattern for generating a hash is `sha1.New()`,
|
// Для генерации хеша используется функция `sha1.New()`,
|
||||||
// `sha1.Write(bytes)`, then `sha1.Sum([]byte{})`.
|
// `sha1.Write(bytes)`, затем `sha1.Sum([]byte{})`.
|
||||||
// Here we start with a new hash.
|
// Тут мы создаем новый хеш.
|
||||||
h := sha1.New()
|
h := sha1.New()
|
||||||
|
|
||||||
// `Write` expects bytes. If you have a string `s`,
|
// В `Write` необходимо передать байты. Если у вас есть
|
||||||
// use `[]byte(s)` to coerce it to bytes.
|
// строка `s`, используйте `[]byte(s)`, чтобы привести
|
||||||
|
// ее к байтам.
|
||||||
h.Write([]byte(s))
|
h.Write([]byte(s))
|
||||||
|
|
||||||
// This gets the finalized hash result as a byte
|
// Получаем окончательный результат хеш-функции в виде
|
||||||
// slice. The argument to `Sum` can be used to append
|
// байтового фрагмента. Аргумент в `Sum` добавляет к
|
||||||
// to an existing byte slice: it usually isn't needed.
|
// существующему фрагменту байты, но обычно он не используется.
|
||||||
bs := h.Sum(nil)
|
bs := h.Sum(nil)
|
||||||
|
|
||||||
// SHA1 values are often printed in hex, for example
|
// Значения SHA1 часто печатаются в шестнадцатеричном формате,
|
||||||
// in git commits. Use the `%x` format verb to convert
|
// например, в git commit. Используйте `%x` для преобразования
|
||||||
// a hash results to a hex string.
|
// результатов хеширования в шестнадцатеричную строку.
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
fmt.Printf("%x\n", bs)
|
fmt.Printf("%x\n", bs)
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
# Running the program computes the hash and prints it in
|
# Запущенная программа вычисляет хеш и печатает его в
|
||||||
# a human-readable hex format.
|
# удобочитаемом шестнадцатеричном формате.
|
||||||
$ go run sha1-hashes.go
|
$ go run sha1-hashes.go
|
||||||
sha1 this string
|
sha1 this string
|
||||||
cf23df2207d99a74fbe169e3eba035e633b65d94
|
cf23df2207d99a74fbe169e3eba035e633b65d94
|
||||||
|
|
||||||
|
# Вы можете вычислить другие хэши, используя шаблон,
|
||||||
|
# аналогичный показанному выше. Например, для вычисления
|
||||||
|
# хэшей MD5 импортируйте `crypto/md5` и используйте `md5.New()`.
|
||||||
|
|
||||||
# You can compute other hashes using a similar pattern to
|
# Обратите внимание, что если вам нужны криптографически
|
||||||
# the one shown above. For example, to compute MD5 hashes
|
# защищенные хэши, вы должны тщательно исследовать
|
||||||
# import `crypto/md5` and use `md5.New()`.
|
# [стойкость хэша](http://en.wikipedia.org/wiki/Cryptographic_hash_function)!
|
||||||
|
|
||||||
# Note that if you need cryptographically secure hashes,
|
|
||||||
# you should carefully research
|
|
||||||
# [hash strength](http://en.wikipedia.org/wiki/Cryptographic_hash_function)!
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user