在键上使用 gpg --list-packets 的输出来获取 mpi 值以生成 s 表达式
我正在尝试使用 gpg 生成的公钥来使用 libgcrypt 进行加密。我在密钥上使用了 list packet 命令来获取密钥的内容,并将 mpi 值解析为 s 表达式。因此,当我尝试使用公钥对会话密钥进行编码时,我收到错误“S 表达式中的奇数十六进制数字”?我认为列表数据包可能给我没有前导零的十六进制数字?如果是这样,我需要做什么才能获得可以在 libgcrypt 中使用的 mpi 值?
I am trying to use gpg generated public keys to do encryption using libgcrypt. I used the list packets command on the key to get me the contents of the key and parsed the mpi values into an s-expression. So when I try to encode my session key with my public key I get the error "Odd hexadecimal numbers in S-expression"? I think list packets is maybe giving me hex numbers without the leading zero? If so what do I need to do to get me mpi values that I can use in libgcrypt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
经过反复试验以及 gpg 和 libgcrypt 邮件列表的建议后,list packet 命令确实会截断 mpi 值中的前导零,因此,在以下情况下,您必须在 mpi 值前面加上零:
进一步说明,使用列表数据包来获取 mpi 值是不明智的,因为它不能可靠地获取 mpi 值,因为它应该是一个可能会发生变化的调试命令。我发现获取公钥和私钥的 mpi 值的最佳方法是通过使用带有 RFC4880 的导出密钥命令对其进行解码来直接解析密钥的二进制导出。
After trial and error and advice from the gpg and libgcrypt mailing lists, the list packets command does truncate the leading zeros from the mpi value and as a result you would have to pre-pend the mpi values with zero(s) when:
As a further note, it is not wise to use list packets to get mpi values as it does not reliably gets you mpi values as it is supposed to be a debugging command which is subject to change. The best way that I have found to get the mpi values for both the public and private keys is to directly parse the binary export of the key by using export key command with RFC4880 to decode it.
您可以使用它来导出密钥:
并使用它来导出公钥:
您可能需要以下工具包:
you can use this to export the secret key:
and this to export the public key:
you may need the following packages for the tools:
我能够使用 pgpdump 获取所需的所有 mpi 值。请务必使用
-i
来告诉它打印所有整数值。唯一奇怪的是 Attilla 发布的公钥命令开头有两个零,而 pgpdump 输出没有。我还不确定是否需要它们。I was able to get all the mpi values I needed by using pgpdump. Be sure to use
-i
which tells it to print all the integer values. The only curious thing is that the public key command that Attilla posted had two zeroes in the beginning that the pgpdump output did not have. I'm not sure if they are needed yet.