无效参数:未找到装甲数据

问题描述

当我尝试加载装甲 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 keyentire signature

解决方法

编辑:我认为这与您的公钥盔甲无效有关。下面是一个工作函数的链接,示例为 const e2ePublicKey public key

他们不使用 strings.NewReader(pubKey),而是使用:

keyring,err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(pubKey))

也许是另一个 bytes.NewBufferString 用于签名。

(来自src

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...