为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我们需要在Go中的Diffie Hellman密钥交换算法中恢复公钥

为什么我们需要在Go中的Diffie Hellman密钥交换算法中恢复公钥

Go
宝慕林4294392 2022-08-24 17:19:43
在本模块文档中(为简单起见,仅考虑 Alice 的一侧),示例代码为:// Get a group. Use the default one would be enough.g, _ := GetGroup(0)// Generate a private key from the group.// Use the default random number generator.priv, _ := g.GeneratePrivateKey(nil)// Get the public key from the private key.pub := priv.Bytes()// Send the public key to Bob.Send("Bob", pub)// Receive a slice of bytes from Bob, which contains Bob's public keyb := Recv("Bob")// Recover Bob's public keybobPubKey := NewPublicKey(b)// Compute the keyk, _ := group.ComputeKey(bobPubKey, priv)// Get the key in the form of []bytekey := k.Bytes()以下是我的问题:1)// Get the public key from the private key.pub := priv.Bytes()如何将私有字节用作公钥字节?它只是方法的命名错误吗?(应该像假设同时包含私钥和公钥一样)priv.GetPubBytes()priv2)// Receive a slice of bytes from Bob, which contains Bob's public keyb := Recv("Bob")// Recover Bob's public keybobPubKey := NewPublicKey(b)如果包含Bob的公钥(通过通道),那么为什么我们需要恢复它?此恢复过程将什么转换为什么?b
查看完整描述

1 回答

?
红糖糍粑

TA贡献1815条经验 获得超6个赞

  1. 是的,它只是命名。我同意你的评论:一个更好的名称应该是类似的东西或明确表明你从公钥获取字节的东西。.GetPubBytes()

  2. 同样,这只是评论的措辞,没有什么可以从网络中恢复的。

请注意,对于像这样的公共包(托管在github上),godoc页面具有指向代码的直接链接。例如:

  • 如果您向下滚动到(本段)的文档条目,func NewPublicKey

  • 单击函数的名称将您带到github上的实现 - 在这种特定情况下:您可以看到唯一的操作是创建一个结构并将字节分配给其字段,这是密钥的公共部分。DHKeyy


查看完整回答
反对 回复 2022-08-24
  • 1 回答
  • 0 关注
  • 99 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号