/kagi

A simple Go utility for managing application keys.

Primary LanguageGoMIT LicenseMIT

kagi (かぎ)

Godoc Reference Latest Version License Name Build Status Coverage Status Go Report Card Status

Package kagi is a simple Go utility for managing application keys. It enables the application to generate and use a secure key on production, while allowing the developers to use hardcoded key that can be shared for the whole team during development.

Features and benefits:

  • Minimal API, it has only two functions.
  • Generates cryptographically secure keys.
  • Supports either generated or hardcoded keys.
  • No imported external dependencies.
  • Properly tested with benchmarks.

Installation

Make sure you have a working Go workspace, then:

go get github.com/h4ckedneko/kagi

For updating to latest stable release, do:

go get -u github.com/h4ckedneko/kagi

Usage

Here is a basic example for this package:

package main

import (
	"fmt"

	"github.com/h4ckedneko/kagi"
)

func main() {
	// Generate a new secure key.
	key := kagi.New(32)
	fmt.Println(key)

	// Decode a generated key.
	keyd := kagi.Decode(key)
	fmt.Println(string(keyd))

	// Decode a hardcoded key.
	keyd = kagi.Decode("abc123")
	fmt.Println(string(keyd))
}

See examples for more advanced real-world examples.

Performance

You can run benchmarks by yourself using make bench command.

BenchmarkNew8-2                  1003131              1168 ns/op              72 B/op          4 allocs/op
BenchmarkNew16-2                 1033360              1193 ns/op             112 B/op          4 allocs/op
BenchmarkNew32-2                  972768              1323 ns/op             192 B/op          4 allocs/op
BenchmarkNew64-2                  627580              1802 ns/op             352 B/op          4 allocs/op
BenchmarkDecodeGenerated-2       8482894               124 ns/op               8 B/op          1 allocs/op
BenchmarkDecodeHardcoded-2      17643516              63.0 ns/op               8 B/op          1 allocs/op

License

MIT © Lyntor Paul Figueroa. See LICENSE for full license text.