在本模块文档中(为简单起见,仅考虑 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个赞
是的,它只是命名。我同意你的评论:一个更好的名称应该是类似的东西或明确表明你从公钥获取字节的东西。
.GetPubBytes()同样,这只是评论的措辞,没有什么可以从网络中恢复的。
请注意,对于像这样的公共包(托管在github上),godoc页面具有指向代码的直接链接。例如:
如果您向下滚动到(本段)的文档条目,
func NewPublicKey单击函数的名称将您带到github上的实现 - 在这种特定情况下:您可以看到唯一的操作是创建一个结构并将字节分配给其字段,这是密钥的公共部分。
DHKeyy
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报
0/150
提交
取消
