Last active
January 20, 2023 18:22
-
-
Save kennwhite/0bf93ba7912ac08ae812 to your computer and use it in GitHub Desktop.
Simple file encryption with Go using pgp (AES128 + SHA256)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"golang.org/x/crypto/openpgp" | |
"io/ioutil" | |
"os" | |
) | |
func main() { | |
/* | |
Equivalent to: | |
gpg -c --symmetric --cipher-algo AES --s2k-digest-algo SHA256 -o test.txt.gpg test.txt | |
# Go 1.4.1/1.5.1 openpgp.SymetricallyEncrypt() docs: "sensible defaults will be used" | |
*/ | |
password := []byte("password") | |
plaintext, _ := ioutil.ReadFile("test.txt") | |
dst, _ := os.Create("test.txt.gpg") | |
encryptor, _ := openpgp.SymmetricallyEncrypt(dst, password, nil, nil) | |
encryptor.Write(plaintext) | |
encryptor.Close() | |
dst.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment