func SaltID(salt, id string, hash HashFunc) string {
	comb := salt + id
	hashVal := hash([]byte(comb))
	return hex.EncodeToString(hashVal)
}
SaltID is used to apply a salt and hash function to an ID to make sure
it is not reversible
package salt
import (
	"crypto/hmac"
	"crypto/sha1"
	"crypto/sha256"
	"encoding/hex"
	"fmt"
	"hash"
	"github.com/hashicorp/go-uuid"
	"github.com/hashicorp/vault/logical"
)
const (
	DefaultLocation = "salt"
)
type Salt struct {
	config    *Config
	salt      string
	generated bool
}
type HashFunc func([]byte) []byte
type Config struct {
	Location string
	HashFunc HashFunc
	HMAC func() hash.Hash
	HMACType string
}
func NewSalt(view logical.Storage, config *Config) (*Salt, error) {
	if config == nil {
		config = &Config{}
	}
	if config.Location == "" {
		config.Location = DefaultLocation
	}
	if config.HashFunc == nil {
		config.HashFunc = SHA256Hash
	}
	if config.HMAC == nil {
		config.HMAC = sha256.New
		config.HMACType = "hmac-sha256"
	}
	s := &Salt{
		config: config,
	}
	var raw *logical.StorageEntry
	var err error
	if view != nil {
		raw, err = view.Get(config.Location)
		if err != nil {
			return nil, fmt.Errorf("failed to read salt: %v", err)
		}
	}
	if raw != nil {
		s.salt = string(raw.Value)
	}
	if s.salt == "" {
		s.salt, err = uuid.GenerateUUID()
		if err != nil {
			return nil, fmt.Errorf("failed to generate uuid: %v", err)
		}
		s.generated = true
		if view != nil {
			raw := &logical.StorageEntry{
				Key:   config.Location,
				Value: []byte(s.salt),
			}
			if err := view.Put(raw); err != nil {
				return nil, fmt.Errorf("failed to persist salt: %v", err)
			}
		}
	}
	if config.HMAC != nil {
		if len(config.HMACType) == 0 {
			return nil, fmt.Errorf("HMACType must be defined")
		}
	}
	return s, nil
}
func (s *Salt) SaltID(id string) string {
	return SaltID(s.salt, id, s.config.HashFunc)
}
func (s *Salt) GetHMAC(data string) string {
	hm := hmac.New(s.config.HMAC, []byte(s.salt))
	hm.Write([]byte(data))
	return hex.EncodeToString(hm.Sum(nil))
}
func (s *Salt) GetIdentifiedHMAC(data string) string {
	return s.config.HMACType + ":" + s.GetHMAC(data)
}
func (s *Salt) DidGenerate() bool {
	return s.generated
}