2

I have some problems with the documentation.

Here is my program:

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())

}

Here are the data:

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

here is the code on gist:

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

What is the public key?

And how to use it?

And how to make bigger key?

peterSO
  • 158,998
  • 31
  • 281
  • 276
Bussiere
  • 500
  • 13
  • 60
  • 119
  • One problem obvious from your script output is that you're not resetting the buffer between each `Serialize` call, so by the end you have all those blobs of data concatenated. Not sure about the other parts of your question. – James Henstridge Mar 20 '13 at 10:22
  • thanks for the buffer. And i would like an example on how to use the key that i've generated thanks. – Bussiere Mar 21 '13 at 10:58

1 Answers1

5

UPDATE: This issue has been fixed: see here

Son the solution/description below is no longer appropriate.

---------------- legacy answer starts below --------------------

Concering your question of How to build keys of an other size: it's impossible.

I ran into the exact same Problem, look at: the source code for the 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 is a pkg-level unexported constant. So no chance of modifing this beheavior.

I ended up copying the whole function out, adding a parameter for the keybits and keeping it in my codebase, if someone has a better solution, I'd be glad to hear it.

tike
  • 2,234
  • 17
  • 19