【问题标题】:openpgp and golangopenpgp 和 golang
【发布时间】:2013-03-18 10:18:16
【问题描述】:

我的文档有些问题。

这是我的程序:

package main

import (
    "bytes"
    "code.google.com/p/go.crypto/openpgp"
    "encoding/base64"
    "fmt"
)

func main() {

    var entity *openpgp.Entity
    entity, err := openpgp.NewEntity("bussiere", "test", "bussiere@gmail.com", nil)
    if err != nil {

    }

    var (
        buffer bytes.Buffer
    )

    entity.SerializePrivate(&buffer, nil)
    data := base64.StdEncoding.EncodeToString([]byte(buffer.String()))

    fmt.Printf("%q\n", data)

    entity.Serialize(&buffer)
    data2 := base64.StdEncoding.EncodeToString([]byte(buffer.String()))

    fmt.Printf("%q\n", data2)

    entity.PrivateKey.Serialize(&buffer)
    data3 := base64.StdEncoding.EncodeToString([]byte(buffer.String()))

    fmt.Printf("%q\n", data3)

    entity.PrimaryKey.Serialize(&buffer)
    data4 := base64.StdEncoding.EncodeToString([]byte(buffer.String()))

    fmt.Printf("%q\n", data4)

    //fmt.Printf(buffer.String())

}

以下是数据:

https://gist.github.com/bussiere/5159890

这里是 gist 上的代码:

https://gist.github.com/bussiere/5159897

什么是公钥?

以及如何使用它?

以及如何制作更大的钥匙?

【问题讨论】:

  • 从您的脚本输出中显而易见的一个问题是,您没有在每个Serialize 调用之间重置缓冲区,因此到最后您将所有这些数据块连接起来。不确定您问题的其他部分。
  • 感谢缓冲区。我想要一个关于如何使用我生成的密钥的例子谢谢。

标签: go pgp openpgp


【解决方案1】:

更新:此问题已修复:see here

儿子下面的解决方案/描述不再合适。

----------------遗留答案从下面开始--------------------

关于如何构建其他大小的密钥的问题:这是不可能的。

我遇到了完全相同的问题,请看:NewEntityFunction 的源代码:

383 const defaultRSAKeyBits = 2048
384 
385 // NewEntity returns an Entity that contains a fresh RSA/RSA keypair with a
386 // single identity composed of the given full name, comment and email, any of
387 // which may be empty but must not contain any of "()<>\x00".
388 // If config is nil, sensible defaults will be used.
389 func NewEntity(name, comment, email string, config *packet.Config) (*Entity, error) {
390     currentTime := config.Now()
391 
392     uid := packet.NewUserId(name, comment, email)
393     if uid == nil {
394         return nil, errors.InvalidArgumentError("user id field contained invalid characters")
395     }
396     signingPriv, err := rsa.GenerateKey(config.Random(), defaultRSAKeyBits)
397     if err != nil {
398         return nil, err
399     }
400     encryptingPriv, err := rsa.GenerateKey(config.Random(), defaultRSAKeyBits)
401     if err != nil {
402         return nil, err
403     }

defaultRSAKeyBits 是一个 pkg 级别的未导出常量。所以没有机会修改这种行为。

我最终复制了整个函数,为密钥位添加了一个参数并将其保存在我的代码库中, 如果有人有更好的解决方案,我会很高兴听到。

【讨论】:

猜你喜欢
  • 2014-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多