Download this file
| 1 | package seal |
| 2 | |
| 3 | import ( |
| 4 | "crypto/hmac" |
| 5 | "encoding/hex" |
| 6 | ) |
| 7 | |
| 8 | // Fingerprint is a keyed, stable digest: equal values give equal |
| 9 | // fingerprints and nothing else can be learned from one. An address is |
| 10 | // enumerable, so a plain hash of it is the address in another alphabet; |
| 11 | // HMAC under a purpose key is not. |
| 12 | func (s *Sealer) Fingerprint(purpose, value string) (string, error) { |
| 13 | key, err := s.purposeKey(purpose) |
| 14 | if err != nil { |
| 15 | return "", err |
| 16 | } |
| 17 | mac := hmac.New(sha256New, key) |
| 18 | mac.Write([]byte(value)) |
| 19 | return hex.EncodeToString(mac.Sum(nil)), nil |
| 20 | } |
| 21 | |