Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Decrypting an ASCII armored GPG encrypted string in Golang
package main
import (
func main() {
decbuf := bytes.NewBuffer([]byte(encryptedMessage))
result, err := armor.Decode(decbuf)
if err != nil {
md, err := openpgp.ReadMessage(result.Body, nil, func(keys []openpgp.Key, symmetric bool) ([]byte, error) {
return []byte("golang"), nil
}, nil)
if err != nil {
fmt.Println("dec version:", result.Header["Version"])
fmt.Println("dec type:", result.Type)
bytes, err := ioutil.ReadAll(md.UnverifiedBody)
fmt.Println("md:", string(bytes))
const encryptedMessage = `-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.15 (Darwin)
-----END PGP MESSAGE-----`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.