当前位置: 首页>>代码示例>>Golang>>正文


Golang openpgp.Entity类代码示例

本文整理汇总了Golang中golang.org/x/crypto/openpgp.Entity的典型用法代码示例。如果您正苦于以下问题:Golang Entity类的具体用法?Golang Entity怎么用?Golang Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Entity类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: writePrivateKeyToFile

func writePrivateKeyToFile(entity *openpgp.Entity, privateKeyFile string) error {
	privKey, err := os.OpenFile(privateKeyFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0400)
	if err != nil {
		return err
	}
	w, err := armor.Encode(
		privKey,
		openpgp.PrivateKeyType,
		map[string]string{
			"Comment": "Key pair generated by generic worker",
		},
	)
	if err != nil {
		return err
	}
	defer func() {
		w.Close()
		fmt.Fprintln(privKey)
		privKey.Close()
	}()
	err = entity.SerializePrivate(w, nil)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:petemoore,项目名称:generic-worker,代码行数:26,代码来源:openpgp.go

示例2: GetArmoredPublicKey

// GetArmoredPublicKey returns an armored public key for entity.
func GetArmoredPublicKey(ent *openpgp.Entity) ([]byte, error) {
	out := new(bytes.Buffer)
	wrt, err := armor.Encode(out, openpgp.PublicKeyType, nil)
	if err != nil {
		return nil, err
	}
	err = ent.Serialize(wrt)
	wrt.Close()
	if err != nil {
		return nil, err
	}
	return out.Bytes(), nil
}
开发者ID:bfix,项目名称:gospel,代码行数:14,代码来源:openpgp.go

示例3: Private

func Private(entity *openpgp.Entity) (string, error) {
	var output bytes.Buffer
	writeBuffer := bufio.NewWriter(&output)
	private, err := armor.Encode(writeBuffer, openpgp.PrivateKeyType, nil)
	if err != nil {
		log.PrintError("authit.crypto.Private", err)
		return "", err
	}

	entity.SerializePrivate(private, nil)
	private.Close()
	writeBuffer.Flush()
	return output.String(), nil
}
开发者ID:authit,项目名称:crypto,代码行数:14,代码来源:create.go

示例4: Public

func Public(entity *openpgp.Entity) (string, error) {
	var output bytes.Buffer
	writeBuffer := bufio.NewWriter(&output)
	public, err := armor.Encode(writeBuffer, openpgp.PublicKeyType, nil)
	if err != nil {
		log.PrintError("telem.crypto.Public", err)
		return "", err
	}

	entity.Serialize(public)
	public.Close()
	writeBuffer.Flush()
	return output.String(), nil
}
开发者ID:pdxjohnny,项目名称:telem,代码行数:14,代码来源:create.go

示例5: writePublicKeyToLog

func writePublicKeyToLog(entity *openpgp.Entity) error {
	w, err := armor.Encode(
		os.Stdout,
		openpgp.PublicKeyType,
		map[string]string{
			"Comment": "Key pair generated by generic worker",
		},
	)
	if err != nil {
		return err
	}
	defer func() {
		w.Close()
		fmt.Println()
	}()
	err = entity.Serialize(w)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:petemoore,项目名称:generic-worker,代码行数:21,代码来源:openpgp.go

示例6: GenerateKey

func GenerateKey(keyFileBase string) (err error) {
	if len(keyFileBase) == 0 {
		return errors.New("key file basename must not be emtpy")
	}
	if isExistingDirectory(keyFileBase) {
		return errors.New("key file basename must not be a directory")
	}

	var f *os.File
	var e *openpgp.Entity
	name, comment, email := entityData()
	e, err = openpgp.NewEntity(name, comment, email, nil)
	if err != nil {
		return err
	}
	for _, id := range e.Identities {
		id.SelfSignature.PreferredSymmetric = []uint8{
			uint8(packet.CipherAES128),
			uint8(packet.CipherAES256),
			uint8(packet.CipherAES192),
			uint8(packet.CipherCAST5),
		}
		id.SelfSignature.PreferredHash = []uint8{
			hashToHashId(crypto.RIPEMD160),
			hashToHashId(crypto.SHA256),
			hashToHashId(crypto.SHA384),
			hashToHashId(crypto.SHA512),
			hashToHashId(crypto.SHA224),
			hashToHashId(crypto.MD5),
		}
		id.SelfSignature.PreferredCompression = []uint8{
			uint8(packet.CompressionNone),
		}
		err := id.SelfSignature.SignUserId(id.UserId.Id, e.PrimaryKey, e.PrivateKey, nil)
		if err != nil {
			return err
		}
	}

	f, err = os.Create(keyFileBase + ".key.asc")
	if err != nil {
		return err
	}
	defer f.Close()
	if err = f.Chmod(0600); err != nil {
		return err
	}
	w, err := armor.Encode(f, openpgp.PrivateKeyType, nil)
	if err != nil {
		return err
	}
	e.SerializePrivate(w, nil)
	w.Close()
	f.Write([]byte{'\n'})

	f, err = os.Create(keyFileBase + ".pub.asc")
	if err != nil {
		return err
	}
	defer f.Close()
	w, err = armor.Encode(f, openpgp.PublicKeyType, nil)
	if err != nil {
		return err
	}
	e.Serialize(w)
	w.Close()
	f.Write([]byte{'\n'})

	return nil
}
开发者ID:thwarted,项目名称:quickpgp,代码行数:70,代码来源:genkey.go


注:本文中的golang.org/x/crypto/openpgp.Entity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。