Skip to content

techjanitor/easyhmac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easyhmac

GoDoc Build Status

Sign arbitrary payloads with HMAC in url safe base64

import "github.com/techjanitor/easyhmac"

Encode and sign message:

	easyhmac.Secret = "secret"

	// Initialize SignedMessage struct with secret
	key := easyhmac.SignedMessage{}

	// Add payload data
	key.Payload = "a cool message"
	
	// Create HMAC signature
	key.Sign()
	
	// Marshal message to JSON and encode in url-safe base64
	signedkey, err := key.Encode()
	if err != nil {
		return
	}

Decode and verify message:

	easyhmac.Secret = "secret"

	// Initialize SignedMessage struct with secret
	message := easyhmac.SignedMessage{}

	// Decode message
	err := message.Decode(ourmessage)
	if err != nil {
		return
	}

	// Verify signature, returns a bool (true if verified)
	check := message.Verify()
	if !check {
		return
	}
	
	payload = message.Payload

About

Sign arbitrary payloads with HMAC in url safe base64

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages