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 ¶
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 ¶
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 ¶
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.