英文:
openpgp and 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", "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
公钥是什么?
如何使用它?
如何生成更大的密钥?
英文:
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?
答案1
得分: 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.
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论