Last active
December 20, 2015 06:59
-
-
Save gobijan/70b50114429e561f80c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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