gencrypt

package module
v0.0.0-...-4012b3f Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2017 License: GPL-2.0 Imports: 3 Imported by: 0

README

Gencrypt: even easier AES256 encryption for Go

Gencrypt is a Go package that acts as a wrapper around portions of the standard libraries crypto package. It depends on only the standard library and is very small at only 40 lines (uncommented, not including tests). Based on George Tankersley's talk at Gophercon 2016.

Example Usage:

package main

import (
  "fmt"

  "gitlab.com/hartsfield/gencrypt"
)

// NOTE: Error checking not handled in this example but should be in
// production.

var (
  // Data you want to encrypt
  data = []byte("test data")
  // Secret key. A 32-byte key is used to indicate AES-256. 16 and 24-byte keys
  // are accepted for AES-128 and AES-192 respectively, but are not
  // recommended.
  key = []byte("12345678901234561234567890123456")
)

func main() {
  // Get the GCM
  gcm, _ := gencrypt.NewGCM(key)

  // Encrypt data
  enc, _ := gcm.AESEncrypt(data)

  // Decrypt data
  dec, _ := gcm.AESDecrypt(enc)
  fmt.Println(string(dec))
}

NOTE:

For those deploying on systems not equipped with CPUs supporting AES-NI [0], you should be aware of possible bottle-necks when it comes to the AES encryption process [1]. > Final caveat, all these recommendations apply only to the amd64 > architecture, for which fast, constant time implementations of the crypto > primitives (AES-GCM, ChaCha20-Poly1305, P256) are available. Other > architectures are probably not fit for production use. [1]

[0] https://en.wikipedia.org/wiki/AES_instruction_set#New_instructions

[1] https://blog.gopheracademy.com/advent-2016/exposing-go-on-the-internet/

Documentation

Overview

gencrypt is a Go package that acts as a wrapper around portions of the standard libraries crypto package.

// NOTE: For those deploying on systems not equipped with CPUs supporting // AES-NI [0], you should be aware of possible bottle-necks when it comes to // the AES encryption process [1]. // >>"Final caveat, all these recommendations apply only to the amd64 // >> architecture, for which fast, constant time implementations of the crypto // >> primitives (AES-GCM, ChaCha20-Poly1305, P256) are available. Other // >> architectures are probably not fit for production use." [1] // [0] https://en.wikipedia.org/wiki/AES_instruction_set#New_instructions // [1] https://blog.gopheracademy.com/advent-2016/exposing-go-on-the-internet/

///////////////////////////////////// // Example Usage: /////////////////// /////////////////////////////////////

package main

import (

"fmt"

"gitlab.com/hartsfield/gencrypt"

)

// NOTE: Error checking not handled in this example but should be in // production

var (

  // Data you want to encrypt
  data = []byte("test data")
  // Secret key. A 32-byte key is used to indicate AES-256. 16 and 24-byte keys
	// are accepted for AES-128 and AES-192 respectively, but are not
	// recommended.
  key = []byte("12345678901234561234567890123456")

)

func main() {
  // Get the GCM
  gcm, _ := gencrypt.NewGCM(key)

  // Encrypt data
  enc, _ := gcm.AESEncrypt(data)

  // Decrypt data
  dec, _ := gcm.AESDecrypt(enc)
  fmt.Println(string(dec))
}

Package gencrypt provides methods for encrypting and decrypting data with the AES encryption method. Based on George Tankersley's talk at Gophercon 2016.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Galois

type Galois struct {
	GCM cipher.AEAD
}

Galois implements the cipher.AEAD interface type (Authenticated Encryption with Associated Data), which allows us to seal and open streams of data, check overhead, and check the nonce size.

func NewGCM

func NewGCM(key []byte) (*Galois, error)

NewGCM takes a key and returns a new Galois struct. A 32-byte key is used to indicate AES-256. 16 and 24-byte keys are accepted for AES-128 and AES-192 respectively, but are not recommended.

func (*Galois) AESDecrypt

func (g *Galois) AESDecrypt(data []byte) ([]byte, error)

AESDecrypt is a method of the Galois struct which decrypts data using the mode (GCM) and returns a decrypted []byte, which can be converted to a type (e.g. string) of the original data.

func (*Galois) AESEncrypt

func (g *Galois) AESEncrypt(data []byte) ([]byte, error)

AESEncrypt is a method of the Galois struct which encrypts data using the mode (GCM) and returns an encrypted []byte.

Jump to

Keyboard shortcuts

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