// +build ignore package main import ( "crypto/rand" "encoding/base64" "fmt" "io/ioutil" "os" "path/filepath" "github.com/jfrazelle/binctr/cryptar" ) const ( nonceSize = 24 ) func main() { // prompt for key wd, err := os.Getwd() if err != nil { panic(err) } out, err := os.Create(filepath.Join(wd, "rootfs.go")) if err != nil { panic(err) } tarPath := filepath.Join(wd, "image.tar") out.Write([]byte("// This file is autogenerated; DO NOT EDIT DIRECTLY\n// See generate.go for more info\npackage main\n\nconst (\n")) out.Write([]byte("\t// DATA is the encrypted tarball data\n")) out.Write([]byte("\tDATA = `")) f, err := ioutil.ReadFile(tarPath) if err != nil { panic(err) } key := make([]byte, 32) if _, err := rand.Read(key); err != nil { panic(err) } gcmOut, err := cryptar.Encrypt(f, key) if err != nil { panic(err) } out.Write([]byte(gcmOut)) out.Write([]byte("`\n")) out.Write([]byte(")\n")) fmt.Println("key is: ", base64.StdEncoding.EncodeToString(key)) }