[英]PGP key armored encoding in Go's openpgp package
I am trying to print a PGP public key in an ASCII armored encoding using Go's openpgp/armor
package. 我正在尝试使用Go的openpgp/armor
包以ASCII装甲编码打印PGP公钥。
The output I would expect: 我期望的输出:
-----BEGIN PGP PUBLIC KEY BLOCK-----
<base64 encoded bytes of public key>
<checksum>
-----END PGP PUBLIC KEY BLOCK-----
The output I get: 我得到的输出:
-----BEGIN PGP PUBLIC KEY BLOCK-----
<first part of base64 encoded bytes of public key>
It only prints the first part of the public key. 它只打印公钥的第一部分。
The public key is obtained from a local keyring file and processed as follows: 公钥是从本地密钥环文件获取的,并按如下方式处理:
keyRingFileBuffer, err := os.Open(keyRingFilePath)
if err != nil {
log.Fatal(err)
}
defer keyRingFileBuffer.Close()
keyRing,err := openpgp.ReadKeyRing(keyRingFileBuffer)
if err != nil {
log.Fatal(err)
}
for _, k := range keyRing {
w, _ := armor.Encode(os.Stdout, openpgp.PublicKeyType, nil)
k.PrimaryKey.Serialize(w)
}
Am I using the package incorrectly? 我不正确地使用包裹吗? Any ideas on how to track the reason for this (in my opinion) wrong output? 关于如何跟踪这个(在我看来)错误输出的原因的任何想法?
Whoops, after putting a bounty on the question I found an answer. 哎呀,在对这个问题给予赏金之后,我找到了答案。 Oh well. 那好吧。
The armor
writer must be closed in order to add that end line. 必须关闭armor
编写器才能添加该终点线。
pubKeyBuf := bytes.NewBuffer(nil)
pubKeyWriter, err := armor.Encode(pubKeyBuf, openpgp.PublicKeyType, nil)
checkIfError(err)
err = e.Serialize(pubKeyWriter)
pubKeyWriter.Close()
checkIfError(err)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.