I am trying to encrypt a file using the Go crypto/aes package. I have so far:
func encrypt(source string, localdir string) error {
src := filepath.Join("/home/bacula/cloud-backup/"+localdir, source)
dst := filepath.Join(src + ".aes")
fmt.Println(src)
fmt.Println(dst)
key := []byte("example key 1234")
iv := []byte(key)[:aes.BlockSize]
aesBlockEncrypter, err := aes.NewCipher([]byte(key))
if err != nil {
return err
}
aesEncrypter := cipher.NewCFBEncrypter(aesBlockEncrypter, iv)
aesEncrypter.XORKeyStream([]byte(dst), []byte(src))
return nil
}
My first question is, how can I improve the way I am generating the IV? And secondly, there is no output file, so how do I stream the file through XORKeyStream?