kagi

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 2 Imported by: 0

README

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.

goos: linux
goarch: amd64
pkg: github.com/h4ckedneko/kagi
cpu: AMD Ryzen 5 5600G with Radeon Graphics
BenchmarkNew8-12                         3424884                374.7 ns/op           64 B/op          4 allocs/op
BenchmarkNew16-12                        3072880                406.5 ns/op           96 B/op          4 allocs/op
BenchmarkNew32-12                        2774564                459.2 ns/op          192 B/op          4 allocs/op
BenchmarkNew64-12                        1826727                648.1 ns/op          352 B/op          4 allocs/op
BenchmarkDecodeGenerated-12             33482005                33.15 ns/op            8 B/op          1 allocs/op
BenchmarkDecodeHardcoded-12             63619456                20.19 ns/op            8 B/op          1 allocs/op
BenchmarkDecodeStringGenerated-12       31331952                39.12 ns/op            8 B/op          1 allocs/op
BenchmarkDecodeStringHardcoded-12       50978620                26.69 ns/op            8 B/op          1 allocs/op
PASS
ok      github.com/h4ckedneko/kagi      11.968s

License

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

Documentation

Overview

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.

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 https://github.com/h4ckedneko/kagi/tree/master/examples for more advanced real-world examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(key string) []byte

Decode decodes an application key and returns its raw bytes. It accepts application key that was generated by New or application key that was manually hardcoded.

func DecodeString added in v1.0.2

func DecodeString(key string) string

DecodeString is like Decode, but it returns the key as string.

func New

func New(size int) string

New returns a randomly generated secure application key.

func New16

func New16() string

New16 is a helper for New that returns a 16-bytes application key.

func New32

func New32() string

New32 is a helper for New that returns a 32-bytes application key.

func New64

func New64() string

New64 is a helper for New that returns a 64-bytes application key.

func New8

func New8() string

New8 is a helper for New that returns an 8-bytes application key.

Types

This section is empty.

Jump to

Keyboard shortcuts

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