crypto


Node.js

  1. const crypto = require('crypto')
  2. const hash = crypto.createHash('sha256').update(Buffer.from('hello')).digest()
  3. console.log(hash.toString('hex'))

Output

  1. 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Go

  1. package main
  2. import (
  3. "crypto/sha256"
  4. "encoding/hex"
  5. "fmt"
  6. )
  7. func main() {
  8. hash := sha256.Sum256([]byte("hello"))
  9. fmt.Println(hex.EncodeToString(hash[:]))
  10. }

Output

  1. 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824