localsecrets

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: Apache-2.0 Imports: 7 Imported by: 18

Documentation

Overview

Package localsecrets provides a secrets implementation using a locally locally provided symmetric key. Use NewKeeper to construct a *secrets.Keeper.

As

localsecrets does not support any types for As.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"gocloud.dev/secrets/localsecrets"
)

func main() {
	// localsecrets.Keeper untilizes the golang.org/x/crypto/nacl/secretbox package
	// for the crypto implementation, and secretbox requires a secret key
	// that is a [32]byte. Because most users will have keys which are strings,
	// the localsecrets package supplies a helper function to convert your key
	// and also crop it to size, if necessary.
	secretKey := localsecrets.ByteKey("I'm a secret string!")
	keeper := localsecrets.NewKeeper(secretKey)

	// Now we can use keeper to encrypt or decrypt.
	plaintext := []byte("Hello, Secrets!")
	ctx := context.Background()
	ciphertext, err := keeper.Encrypt(ctx, plaintext)
	if err != nil {
		log.Fatal(err)
	}
	decrypted, err := keeper.Decrypt(ctx, ciphertext)
	fmt.Println(string(decrypted))

}
Output:

Hello, Secrets!

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteKey

func ByteKey(sk string) [32]byte

ByteKey takes a secret key as a string and converts it to a [32]byte, cropping it if necessary.

func NewKeeper

func NewKeeper(sk [32]byte) *secrets.Keeper

NewKeeper returns a *secrets.Keeper that uses the given symmetric key. See the package documentation for an example.

Types

This section is empty.

Jump to

Keyboard shortcuts

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