How do I use Go's openpgp package?

独自空忆成欢 提交于 2019-12-12 10:45:09

问题


I've been looking through the documentation for Go's openpgp package, and I think I must be missing some obvious points. For example, there's a ReadKeyRing function, but no WriteKeyRing. I can, on the other hand, Serialize an Entity, but I have no way to read it back. What's going on here? Does anyone actually use this package?


回答1:


An entity represents public+private GPG key information. The ReadKeyRing function allows you to read a list of GPG keys.

The Entity.Serialize function documentation states:

Serialize writes the public part of the given Entity to w. (No private key material will be output).

As it is only the public part of the entity, you can create a new entity with the serialized data as the public key.

A WriteKeyRing does indeed not exist. It would go through the list of entities and extract the public keys into an array.




回答2:


I was also struggeling quite a lot with this - in the end I just learned it by example:

  • Encryption and Decryption example: https://gist.github.com/jyap808/8250124
  • Decryption Example: https://gist.github.com/jyap808/8250067

The thinking behind this is not made for a user, but seems to come strongly out of the actual way pgp is technically implemented.

I would suggest to generate the keys not via the package but just with a pgp command line tool.



来源:https://stackoverflow.com/questions/7775181/how-do-i-use-gos-openpgp-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!