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

在本模块文档中(为简单起见,仅考虑 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 key

b := Recv("Bob")


// Recover Bob's public key

bobPubKey := NewPublicKey(b)


// Compute the key

k, _ := group.ComputeKey(bobPubKey, priv)


// Get the key in the form of []byte

key := k.Bytes()

以下是我的问题:


1)


// Get the public key from the private key.

pub := priv.Bytes()

如何将私有字节用作公钥字节?它只是方法的命名错误吗?(应该像假设同时包含私钥和公钥一样)priv.GetPubBytes()priv


2)


// Receive a slice of bytes from Bob, which contains Bob's public key

b := Recv("Bob")


// Recover Bob's public key

bobPubKey := NewPublicKey(b)

如果包含Bob的公钥(通过通道),那么为什么我们需要恢复它?此恢复过程将什么转换为什么?b


宝慕林4294392
浏览 100回答 1
1回答

红糖糍粑

是的,它只是命名。我同意你的评论:一个更好的名称应该是类似的东西或明确表明你从公钥获取字节的东西。.GetPubBytes()同样,这只是评论的措辞,没有什么可以从网络中恢复的。请注意,对于像这样的公共包(托管在github上),godoc页面具有指向代码的直接链接。例如:如果您向下滚动到(本段)的文档条目,func NewPublicKey单击函数的名称将您带到github上的实现 - 在这种特定情况下:您可以看到唯一的操作是创建一个结构并将字节分配给其字段,这是密钥的公共部分。DHKeyy
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go