Created
June 29, 2013 22:48
-
-
Save marete/5893004 to your computer and use it in GitHub Desktop.
I am currently reviewing Go's OpenPGP implementation with a view of possibly implementing bzip2 support for it, as well as testing compatibility with GNUPG. This is a simple GIST that shows how to decrypt a symmetrically encrypted file using go.crypto/openpgp. It can be useful for testing go.crypto/openpgp compatibility with various symmetric ci…
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 ( | |
"code.google.com/p/go.crypto/openpgp" | |
"errors" | |
"io" | |
"log" | |
"os" | |
) | |
// An empty Keyring | |
type emptyKR struct { | |
} | |
func (kr emptyKR) KeysById(id uint64) []openpgp.Key { | |
return nil | |
} | |
func (kr emptyKR) DecryptionKeys() []openpgp.Key { | |
return nil | |
} | |
const passphrase = "eisae4Iid8Jac2ee" | |
func promptFunction(keys []openpgp.Key, symmetric bool) ([]byte, error) { | |
if !symmetric { | |
// We only support passhphrases for symmetrically | |
// encrypted decryption keys | |
return nil, errors.New("Decrypting private keys not supported") | |
} | |
return []byte(passphrase), nil | |
} | |
func main() { | |
file, err := os.Open("message.txt.gpg") | |
if err != nil { | |
log.Fatalln(err) | |
} | |
md, err := openpgp.ReadMessage(file, emptyKR{}, promptFunction, nil) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
_, err = io.Copy(os.Stdout, md.UnverifiedBody) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
// Check that any authentication code for the message was | |
// verified successfully | |
if md.SignatureError != nil { | |
log.Fatalln("Integrity Check FAILED:", md.SignatureError) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment