enc

package module
v0.0.0-...-96b6193 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: MIT Imports: 8 Imported by: 0

README

enc Build Status Go Report Card Test Coverage Go Docs

Small utility library to perform symmetric AES encryption in Go. Mini example:

ciphertext, err := enc.Encrypt(key, plaintext)
if err != nil {
  ...
}

plaintext, err := enc.Decrypt(key, ciphertext)
if err != nil {
  ...
}

It is also possible to automatically encode/decode the plaintext and ciphertext using a known []byte <-> string encoding such as base64.StdEncoding:

encodedCiphertext, err := enc.EncryptWithEncoding(key, base64.StdEncoding, plaintext)
if err != nil {
  ...
}

plaintext, err := enc.DecryptWithEncoding(key, base64.StdEncoding, ciphertext)
if err != nil {
  ...
}

Documentation

Index

Constants

View Source
const (
	// KeySize is the required key size, in bytes.
	KeySize = 32
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key [KeySize]byte, ciphertext []byte) ([]byte, error)

Decrypt decrypts a ciphertext encrypted by Encrypt.

func DecryptWithEncoding

func DecryptWithEncoding(key [KeySize]byte, encoding Encoding, encodedCiphertext string) ([]byte, error)

DecryptWithEncoding is like Decrypt, but first decodes the ciphertext from string using the given Encoding.

func Encrypt

func Encrypt(key [KeySize]byte, plaintext []byte) ([]byte, error)

Encrypt encrypts the given plaintext using symmetric AES, GCM mode.

func EncryptWithEncoding

func EncryptWithEncoding(key [KeySize]byte, encoding Encoding, plaintext []byte) (string, error)

EncryptWithEncoding is like Encrypt, but also encodes the ciphertext to string using the given Encoding.

Types

type Encoding

type Encoding interface {
	EncodeToString(src []byte) string
	DecodeString(s string) ([]byte, error)
}

Encoding describes a []byte <-> string encoding algorithm, such as base64.StdEncoding and others.

Jump to

Keyboard shortcuts

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