Skip to content

Instantly share code, notes, and snippets.

@gobijan
Last active December 20, 2015 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gobijan/70b50114429e561f80c8 to your computer and use it in GitHub Desktop.
Save gobijan/70b50114429e561f80c8 to your computer and use it in GitHub Desktop.
// There seem to be problems with "climatically" and "fezzes" as passwords.
// When using "climatically": Program terminates with "openpgp: unsupported feature: public key version"
// When using "fezzes": Program terminates with "openpgp: invalid data: tag byte does not have MSB set"
// Expected behaviour would be a reinvokation of the prompt function in an endless loop until the right password is used.
package main
import (
"bytes"
"errors"
"io/ioutil"
"log"
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/armor"
)
func prompt(keys []openpgp.Key, symmetric bool) ([]byte, error) {
if !symmetric {
return nil, errors.New("Decrypting private keys not supported")
}
return []byte("climatically"), nil
// return []byte("fezzes"), nil // also causes error
}
func main() {
// This message is ecrypted witht the password "password"
message := []byte(`-----BEGIN PGP MESSAGE-----
Version: GnuPG v1
jA0ECQMCIFOMjWmWTZZg0kABHIkMAZskzkav2QZQAJStGv3k1WuWZt7pVozy1HMV
s25QGzQIE6Yri4K3JJKwCkWVlB69lt6Oq2NqACELxXoT
=zze7
-----END PGP MESSAGE-----`)
decbuf := bytes.NewBuffer(message)
result, err := armor.Decode(decbuf)
if err != nil {
log.Fatal(err)
}
md, err := openpgp.ReadMessage(result.Body, nil, prompt, nil)
if err != nil {
log.Fatalln(err)
}
bytes, err := ioutil.ReadAll(md.UnverifiedBody)
println(string(bytes))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment