2013-03-18 26 views
2

我有一些文檔問題。openpgp和golang

這裏是我的程序:

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", "[email protected]", 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 

什麼是公共密鑰?

以及如何使用它?

如何做出更大的關鍵?

+0

從腳本輸出中可以看出一個問題,就是你沒有重置每個'Serialize'調用之間的緩衝區,所以最後你將所有這些數據連接起來。不確定你的問題的其他部分。 – 2013-03-20 10:22:04

+0

感謝您的緩衝區。我想要一個關於如何使用我產生的感謝的關鍵的例子。 – user462794 2013-03-21 10:58:27

回答

4

更新:此問題已得到修復:see here

兒子的解決方案/下面的說明是不再適宜。

----------------傳統答案下面開始--------------------

Concering your如何構建其他尺寸的按鍵問題:這是不可能的。

我跑進完全相同的問題,看:用於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-水平未導出常數。所以沒有機會修改這個beheavior。

我最終複製了整個函數,爲keybits添加一個參數並將其保存在我的代碼庫中,如果有人有更好的解決方案,我很樂意聽到它。

+1

這個答案是正確的。我們正在修復它:https://github.com/golang/go/issues/6693 – 2015-07-21 15:41:39