No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

35 líneas
591 B

  1. package common
  2. import (
  3. "crypto/hmac"
  4. "crypto/sha1"
  5. "crypto/sha256"
  6. "encoding/hex"
  7. )
  8. func Sha256Raw(data []byte) []byte {
  9. h := sha256.New()
  10. h.Write(data)
  11. return h.Sum(nil)
  12. }
  13. func Sha1Raw(data []byte) []byte {
  14. h := sha1.New()
  15. h.Write(data)
  16. return h.Sum(nil)
  17. }
  18. func Sha1(data []byte) string {
  19. return hex.EncodeToString(Sha1Raw(data))
  20. }
  21. func HmacSha256Raw(message, key []byte) []byte {
  22. h := hmac.New(sha256.New, key)
  23. h.Write(message)
  24. return h.Sum(nil)
  25. }
  26. func HmacSha256(message, key string) string {
  27. return hex.EncodeToString(HmacSha256Raw([]byte(message), []byte(key)))
  28. }