User Tools

Site Tools


go:stdlib:crypto_sha256

crypto/sha256

What is it?

`crypto/sha256` provides the SHA-256 cryptographic hash function.

What is it used for?

  • Generate a fixed-length digest (hash) from data.
  • Verify integrity (data has not changed).
  • Used in signatures, checksums, and many security protocols.

Example (Sum256)

package main
 
import (
    "crypto/sha256"
    "fmt"
)
 
func main() {
    sum := sha256.Sum256([]byte("hello"))
    fmt.Printf("%x\n", sum)
}

Notes

  • SHA-256 is a hash, not encryption.
  • For password hashing, use `bcrypt/scrypt/argon2` (do not use plain SHA-256).

Hard words (English)

  • digest /ˈdaɪdʒest/: bản băm (kết quả hash)
  • integrity /ɪnˈteɡrɪti/: tính toàn vẹn
  • encryption /ɪnˈkrɪpʃən/: mã hoá
  • checksum /ˈtʃeksʌm/: mã kiểm tra
go/stdlib/crypto_sha256.txt · Last modified: by phong2018