Esempio n. 1
0
// SignedBase64 converts the map to a base64 string and signs it using the
// provided key. The returned data is the base64 string plus an appended signature.
//
// Will return an error if Base64ing the map fails.
func (d Map) SignedBase64(key string) (string, error) {

	base64, err := d.Base64()
	if err != nil {
		return "", err
	}

	sig := signature.HashWithKey([]byte(base64), []byte(key))

	return base64 + SignatureSeparator + sig, nil

}
Esempio n. 2
0
// HashWithKey gets the a hash of the map, signed by the
// specified security key.
//
// Will return an error if Base64ing the map fails.
func (d Map) HashWithKey(key string) (string, error) {

	base64, err := d.Base64()
	if err != nil {
		return "", err
	}

	sig := signature.HashWithKey([]byte(base64), []byte(key))

	return sig, nil

}
Esempio n. 3
0
// NewMapFromSignedBase64String creates a new map from a signed Base64 string representation
func NewMapFromSignedBase64String(data, key string) (Map, error) {

	parts := strings.Split(data, SignatureSeparator)
	if len(parts) != 2 {
		return nil, errors.New("Map: Signed base64 string is malformed.")
	}

	sig := signature.HashWithKey([]byte(parts[0]), []byte(key))
	if parts[1] != sig {
		return nil, errors.New("Map: Signature for Base64 data does not match.")
	}

	return NewMapFromBase64String(parts[0])

}