Skip to content

Latest commit

 

History

History
57 lines (44 loc) · 1.75 KB

README.md

File metadata and controls

57 lines (44 loc) · 1.75 KB

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"
  "github.com/btcsuite/btcutil/base58"
  "github.com/attiliodrei/gencrypt"
)

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

var (
  // Data you want to encrypt
  data = []byte("/restreamer/footters_client/footters-27/restreamer/hls/UGE8b2g/")
  // 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)
  b58enc := base58.Encode([]byte(enc))
  fmt.Println(string(b58enc))
  // Decrypt data
  dec, _ := gcm.AESDecrypt(base58.Decode(b58enc))
  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/