我的文档有问题。

这是我的程序:

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

这是要点上的代码:
https://gist.github.com/bussiere/5159897

什么是公钥?

以及如何使用?

以及如何制作更大的 key ?

最佳答案

更新:此问题已得到解决: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级未导出的常量。因此,没有机会修改这种行为。

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

07-27 13:42