问题描述
当我尝试加载装甲 GPG 公钥以验证签名时,出现错误 openpgp: invalid argument: no armored data found
我的代码(一些数据被缩短以更好地适应):
pubKey := `-----BEGIN PGP PUBLIC KEY BLOCK-----
xsFNBF/9Xn [...] =Yo8+
-----END PGP PUBLIC KEY BLOCK-----`
content := "Hello World"
signature := `-----BEGIN PGP SIGNATURE-----
wsFcBAE [...] =z3nL
-----END PGP SIGNATURE-----`
keyring,err := openpgp.ReadArmoredKeyRing(strings.NewReader(pubKey))
if err != nil {
// Errors out here with: openpgp: invalid argument: no armored data found
// ...
}
// Code never gets this far but I'm including this in case I'm using it all wrong...
_,err = openpgp.CheckArmoredDetachedSignature(keyring,strings.NewReader(content),strings.NewReader(signature))
if err != nil {
return false,err
}
Entire public key,entire signature。
解决方法
编辑:我认为这与您的公钥盔甲无效有关。下面是一个工作函数的链接,示例为 const e2ePublicKey
public key。
他们不使用 strings.NewReader(pubKey)
,而是使用:
keyring,err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(pubKey))
也许是另一个 bytes.NewBufferString
用于签名。
(来自src)