guth

package module
v0.0.0-...-cecb815 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2016 License: MIT Imports: 8 Imported by: 0

README

Guth

Simple, Stateless, Secure

GoDoc

Guth implements a secure stateless authentication in golang.

Installation

go get github.com/huijari/guth

Usage example

Creation:

payload := Payload{
  Content: "6ba7b810-9dad-11d2-80b4-00c04fd430c8", // Eg. user id
  Created: time.Now(), // Date of creation (of the token)
}

Encrypt:

key := []byte("0123456789abcdef") // AES key
token, err := payload.Encrypt(key)
if err != nil {
  log.Fatal("Encrypt error", err)
}

Decrypt:

err = payload.Decrypt(token, key)
if err != nil {
  log.Fatal("Decrypt", err)
}

Notice

This package isn't under development.

Meta

Distributed under the MIT license. See LICENSE for more information.

Huijari

Documentation

Overview

Guth implements a secure stateless authentication in golang.

Creation:

payload := Payload{
  Content: "6ba7b810-9dad-11d2-80b4-00c04fd430c8", // Eg. user id
  Created: time.Now(), // Date of creation (of the token)
}

Encrypt:

key := []byte("0123456789abcdef") // AES key
token, err := payload.Encrypt(key)
if err != nil {
  log.Fatal("Encrypt error", err)
}

Decrypt:

err = payload.Decrypt(token, key)
if err != nil {
  log.Fatal("Decrypt error", err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Payload

type Payload struct {
	Content string
	Created time.Time
}

What the token will carry

func (*Payload) Decrypt

func (this *Payload) Decrypt(encrypted []byte, key []byte) (err error)

Retrieve payload from token using an AES key

func (Payload) Encrypt

func (this Payload) Encrypt(key []byte) (result []byte, err error)

Generate token from payload using an AES key

func (Payload) MarshalBinary

func (this Payload) MarshalBinary() (result []byte, err error)

Marshal payload to []byte

func (*Payload) UnmarshalBinary

func (this *Payload) UnmarshalBinary(data []byte) (err error)

Unmarshal payload from []byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL