Instantly share code, notes, and snippets.

Embed
What would you like to do?
GPG signature verification in Go with a bunch of strings
package main [33/492]
import (
"fmt"
"strings"
"golang.org/x/crypto/openpgp"
)
func main() {
keyRingReader := strings.NewReader(`
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: Keybase OpenPGP JS 0.0.1
Comment: https://keybase.io/fiatjaf
xsFNBFMwdocBEAC1ccQla+3neDTlSvISDIEcrpaxIbb39fDs17yCPsZ47lGpu776
rUZc4dLr/pXmdlz8gVVJpcctWHxkjLadnI5vwJIl2n0TOZe3wQsmW2I+HZtRnPnU
aSvmGu8h8/HDsdlr8M0xHMnBGkCF5Z5CeD/51H0NS1rmHbV+ZtYNijgiX62a3T3S
dweMlf5Dr5f3U1A+kBYrjngspVG4JfzQCcj12wTV6LEk87g20skyNqezuW1VcdBm
Yfta7eLS1Iq8GLuHF3dxvnJk/VwWeg3E6G/ZKZxr3z4lnQbxuDhuWJNmtM40vxP2
bS0infStzVFaBMChfm+/WCWcv6RrPubd8TTU884rCDZRvCQtNnBfk5Q7N1vmDEbP
ICu/plZ+qfPVmKhapvVbbsztbtPADJEpQGwj8PT4WhR2CCBPXo8bGNda0RuAjj27
dG4/zzO6pUf6q0YuyxcXaKrVrU3ojp4l4S4OurUWwcfgxrwF38OlQFq5DGWf/h6K
yq+syWemBbKkVUvZh2C3rEDLuJ5wIZ7OsGzn37sAoaQtE6Skji32jyEFGqVt9Qen
dXU1uNcsyBIgIMafCgewW4pRm4dlipkd2cBVsuUVq5dT2DDdpCNwssWAq2L96HMn
+fsvL+yJpE3oVBVdvtynLtcY9xYhHMEv6+ZZd+dpw2nbS87ziqs0Gt9nQQARAQAB
zSdrZXliYXNlLmlvL2ZpYXRqYWYgPGZpYXRqYWZAa2V5YmFzZS5pbz7CwW0EEwEK
ABcFAlMwdocCGy8DCwkHAxUKCAIeAQIXgAAKCRCPgQIDZETN0puMD/95pQYLdiUC
rVUioOIPmsXc7HsaKeL1J3r3L+wIAzFO8namczvGdFH3nOM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PUBLIC KEY BLOCK-----
`)
signature := strings.NewReader(`
-----BEGIN PGP SIGNATURE-----
wsBcBAABCAAQBQJZxpqaCRACbO6WzpfsagAAGxUIADhrhyJUG9zsDMDdDSBtDYE5
H/I5eRxMbklF/LCGF67UXQHYcqi0sxDK/NR4Ld9iUhrj/g/hqqGdo03gDKL9FTMJ
3D6ttSBjkv9eacXaRSxBFsQHwXGU1mC5ZR6mCsxyfLESNxd27s8/5sP+62AkhC17
hqFpp/n2gcUn9dOd0X/pUQ+0RV6GZWQlSg/ds4Ff0dX5d7+z30xqhMPuGKfxZIk6
57AjmbYvkoRaMkbVLl7uIDVkt30Ww/WLoL8KyOl+NDwfl6d8TX3MalfidDd7kvad
11L9/ZZ6SuFNXPaMDsZomThuz8/J+qAfdyHBV8xyz2bTXa2SJNxdxtkUf3m+1rA=
=5/WZ
-----END PGP SIGNATURE-----
`)
verification_target := strings.NewReader(`bla
`)
keyring, err := openpgp.ReadArmoredKeyRing(keyRingReader)
if err != nil {
fmt.Println("Read Armored Key Ring: " + err.Error())
return
}
entity, err := openpgp.CheckArmoredDetachedSignature(keyring, verification_target, signature)
if err != nil {
fmt.Println("Check Detached Signature: " + err.Error())
return
}
fmt.Println(entity)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment