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


Golang openpgp.ReadKeyRing函数代码示例

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


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

示例1: encryptOpenpgp

func encryptOpenpgp(data io.Reader, recipient string, gpghome string) ([]byte, error) {
	pubkeyfile, err := os.Open(fmt.Sprintf("%s%spubring.gpg", gpghome, string(os.PathSeparator)))
	if err != nil {
		fmt.Println("Failed to open pubring", err)
		return nil, err
	}

	pubring, err := openpgp.ReadKeyRing(pubkeyfile)
	if err != nil {
		fmt.Println("Failed to open pubring", err)
		return nil, err
	}

	pubkey := findKey(pubring, recipient)

	buf := bytes.NewBuffer(nil)
	w, _ := armor.Encode(buf, "PGP MESSAGE", nil)
	plaintext, err := openpgp.Encrypt(w, []*openpgp.Entity{pubkey}, nil, nil, nil)
	if err != nil {
		return nil, err
	}
	//reader := bytes.NewReader(data)
	_, err = io.Copy(plaintext, data)
	plaintext.Close()
	w.Close()
	if err != nil {
		return nil, err
	}

	return buf.Bytes(), nil

}
开发者ID:jamesunger,项目名称:ipboh,代码行数:32,代码来源:ipboh.go

示例2: processPublicKeyRing

func processPublicKeyRing() (entity *openpgp.Entity, entitylist openpgp.EntityList) {
	// TODO: Handle a specified recipient
	// Get default public keyring location
	usr, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}

	jaegerPublicKeyRing := fmt.Sprintf("%v/.gnupg/jaeger_pubring.gpg", usr.HomeDir)
	publicKeyRing := ""

	if _, err := os.Stat(jaegerPublicKeyRing); err == nil {
		publicKeyRing = jaegerPublicKeyRing
	} else {
		publicKeyRing = fmt.Sprintf("%v/.gnupg/pubring.gpg", usr.HomeDir)
	}

	debug.Printf("publicKeyRing file:", publicKeyRing)
	publicKeyRingBuffer, err := os.Open(publicKeyRing)
	if err != nil {
		panic(err)
	}
	entitylist, err = openpgp.ReadKeyRing(publicKeyRingBuffer)
	if err != nil {
		log.Fatal(err)
	}

	entity = entitylist[0]
	debug.Printf("Public key default keyring:", entity.Identities)

	return entity, entitylist
}
开发者ID:gitmonster,项目名称:jaeger,代码行数:32,代码来源:jaegerdb.go

示例3: loadKeyring

func loadKeyring(keyringReader io.Reader) (openpgp.EntityList, error) {
	entityList, err := openpgp.ReadKeyRing(keyringReader)
	if err != nil {
		return entityList, err
	}
	return entityList, nil
}
开发者ID:laher,项目名称:passr,代码行数:7,代码来源:gpg.go

示例4: LoadKeyring

func LoadKeyring(path string) (openpgp.EntityList, error) {
	if path == "" {
		return nil, util.Errorf("no keyring configured")
	}
	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	// Accept both ASCII-armored and binary encodings
	keyring, err := openpgp.ReadArmoredKeyRing(f)
	if err != nil && err.Error() == "openpgp: invalid argument: no armored data found" {
		offset, seekErr := f.Seek(0, os.SEEK_SET)
		if offset != 0 || seekErr != nil {
			return nil, util.Errorf(
				"couldn't seek to beginning, got %d %s",
				offset,
				seekErr,
			)
		}
		keyring, err = openpgp.ReadKeyRing(f)
	}

	return keyring, err
}
开发者ID:petertseng,项目名称:p2,代码行数:26,代码来源:auth_policy.go

示例5: enc

func enc(i int, keyRingHex string, keyName string, isSigned bool, filename string, message string, passphraseS string) error {
	kring, err := openpgp.ReadKeyRing(ReaderFromHex(keyRingHex))
	if err != nil {
		return err
	}
	return Encrypt(i, kring, keyName, isSigned, filename, message)
}
开发者ID:laher,项目名称:passr,代码行数:7,代码来源:gpg.go

示例6: Encode

// Encode encodes data to a base64 encoded using the secconf codec.
// data is encrypted with all public keys found in the supplied keyring.
func Encode(data []byte, keyring io.Reader) ([]byte, error) {
	entityList, err := openpgp.ReadKeyRing(keyring)
	if err != nil {
		return nil, err
	}
	return encode(data, entityList)
}
开发者ID:jsipprell,项目名称:crypt,代码行数:9,代码来源:secconf.go

示例7: checkGPGSig

func checkGPGSig(fileName string, sigFileName string) error {

	// Get a Reader for the signature file
	sigFile, err := os.Open(sigFileName)
	if err != nil {
		return err
	}
	defer sigFile.Close()

	// Get a Reader for the signature file
	file, err := os.Open(fileName)
	if err != nil {
		return err
	}
	defer file.Close()

	publicKeyBin, err := hex.DecodeString(publicKeyHex)
	if err != nil {
		return err
	}

	keyring, _ := openpgp.ReadKeyRing(bytes.NewReader(publicKeyBin))

	_, err = openpgp.CheckDetachedSignature(keyring, file, sigFile)

	return err
}
开发者ID:arduino,项目名称:arduino-create-agent,代码行数:27,代码来源:download.go

示例8: FetchEntity

func (fe *FileEntityFetcher) FetchEntity(keyId string) (*openpgp.Entity, error) {
	f, err := wkfs.Open(fe.File)
	if err != nil {
		return nil, fmt.Errorf("jsonsign: FetchEntity: %v", err)
	}
	defer f.Close()
	el, err := openpgp.ReadKeyRing(f)
	if err != nil {
		return nil, fmt.Errorf("jsonsign: openpgp.ReadKeyRing of %q: %v", fe.File, err)
	}
	for _, e := range el {
		pubk := &e.PrivateKey.PublicKey
		if pubk.KeyIdString() != keyId {
			continue
		}
		if e.PrivateKey.Encrypted {
			if err := fe.decryptEntity(e); err == nil {
				return e, nil
			} else {
				return nil, err
			}
		}
		return e, nil
	}
	return nil, fmt.Errorf("jsonsign: entity for keyid %q not found in %q", keyId, fe.File)
}
开发者ID:camlistore,项目名称:camlistore,代码行数:26,代码来源:sign.go

示例9: Insert

func Insert(publicKeyringFile, keyName, fdir, name, pass string) error {
	message := pass
	filename := filepath.Join(fdir, fmt.Sprintf("%s.gpg", name))
	_, err := os.Stat(filename)
	if err != nil {
		if !os.IsNotExist(err) {
			return err
		}
	} else {
		return fmt.Errorf("file %s exists", filename)
	}
	keyringFileBuffer, err := os.Open(publicKeyringFile)
	if err != nil {
		return err
	}
	defer func() {
		err := keyringFileBuffer.Close()
		if err != nil {
			logrus.Errorf("Error closing file %s", err)
		}
	}()
	kring, err := openpgp.ReadKeyRing(keyringFileBuffer)
	if err != nil {
		return err
	}
	err = Encrypt(0, kring, keyName, false, filename, message)
	return err
}
开发者ID:laher,项目名称:passr,代码行数:28,代码来源:insert.go

示例10: findKey

func findKey(key string) (*openpgp.Entity, error) {
	keyId, err := strconv.ParseUint(key, 16, 64)
	if err != nil {
		log.Printf("Unable to parse key '%s': %s\n", key, err)
		return nil, &UnknownKey{key}
	}
	f, err := os.Open(KeyringFile)
	if err != nil {
		log.Printf("Failed to open keyring: %s\n", err)
		return nil, err
	}
	defer f.Close()
	el, err := openpgp.ReadKeyRing(f)
	if err != nil {
		log.Printf("Failed to read keyring: %s\n", err)
		return nil, err
	}
	for _, entity := range el {
		if entity.PrimaryKey.KeyId&0xFFFFFFFF == keyId {
			return entity, nil
		}
		for _, key := range entity.Subkeys {
			if key.PublicKey.KeyId&0xFFFFFFFF == keyId {
				return entity, nil
			}
		}
	}
	return nil, &UnknownKey{key}
}
开发者ID:qur,项目名称:repo_server,代码行数:29,代码来源:opgp.go

示例11: processSecretKeyRing

func processSecretKeyRing() (entity *openpgp.Entity, entitylist openpgp.EntityList) {
	// Get default secret keyring location
	usr, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}

	jaegerSecretKeyRing := fmt.Sprintf("%v/.gnupg/jaeger_secring.gpg", usr.HomeDir)
	secretKeyRing := ""

	if _, err := os.Stat(jaegerSecretKeyRing); err == nil {
		secretKeyRing = jaegerSecretKeyRing
	} else {
		secretKeyRing = fmt.Sprintf("%v/.gnupg/secring.gpg", usr.HomeDir)
	}

	debug.Printf("secretKeyRing file:", secretKeyRing)
	secretKeyRingBuffer, err := os.Open(secretKeyRing)
	if err != nil {
		panic(err)
	}
	entitylist, err = openpgp.ReadKeyRing(secretKeyRingBuffer)
	if err != nil {
		log.Fatal(err)
	}

	entity = entitylist[0]
	debug.Printf("Private key default keyring:", entity.Identities)

	return entity, entitylist
}
开发者ID:gitmonster,项目名称:jaeger,代码行数:31,代码来源:jaeger.go

示例12: main

func main() {
	//NewEntity("hyg", "[email protected]", "secfile.key")
	//return

	pubringFile, _ := os.Open("path to public keyring")
	defer pubringFile.Close()
	pubring, _ := openpgp.ReadKeyRing(pubringFile)
	//theirPublicKey := getKeyByEmail(pubring, "[email protected]")
	theirPublicKey := getKeyByEmail(pubring, "[email protected]")

	secringFile, _ := os.Open("path to private keyring")
	defer secringFile.Close()
	sevring, _ := openpgp.ReadKeyRing(secringFile)
	myPrivateKey := getKeyByEmail(sevring, "[email protected]")

	//theirPublicKey.Serialize(os.Stdout)
	//myPrivateKey.Serialize(os.Stdout)
	//myPrivateKey.SerializePrivate(os.Stdout, nil)

	myPrivateKey.PrivateKey.Decrypt([]byte("passphrase"))
	/*
		// bug: have to input the correct passphrase at the first time

		for myPrivateKey.PrivateKey.Encrypted {
			fmt.Print("PGP passphrase: ")
			pgppass := gopass.GetPasswd()

			myPrivateKey.PrivateKey.Decrypt([]byte(pgppass))
			if myPrivateKey.PrivateKey.Encrypted {
				fmt.Println("Incorrect. Try again or press ctrl+c to exit.")
			}
		}
	*/

	var hint openpgp.FileHints
	hint.IsBinary = false
	hint.FileName = "_CONSOLE"
	hint.ModTime = time.Now()

	w, _ := armor.Encode(os.Stdout, "PGP MESSAGE", nil)
	defer w.Close()
	plaintext, _ := openpgp.Encrypt(w, []*openpgp.Entity{theirPublicKey}, myPrivateKey, &hint, nil)
	defer plaintext.Close()

	fmt.Fprintf(plaintext, "黄勇刚在熟悉OpenPGP代码\n")
}
开发者ID:hyg,项目名称:go.sample,代码行数:46,代码来源:main.go

示例13: ReadKeyRing

func ReadKeyRing(keyRingName string) (openpgp.EntityList, error) {
	keyfile, err := os.Open(keyRingName)
	if err != nil {
		return nil, err
	}
	defer keyfile.Close()
	return openpgp.ReadKeyRing(keyfile)
}
开发者ID:zennro,项目名称:oyster,代码行数:8,代码来源:crypto.go

示例14: EncodeWith

func EncodeWith(data []byte, keyring io.Reader, f EntityFilter) ([]byte, error) {
	entityList, err := openpgp.ReadKeyRing(keyring)
	if err != nil {
		return nil, err
	}

	return encode(data, f.Entities(entityList...))
}
开发者ID:jsipprell,项目名称:crypt,代码行数:8,代码来源:secconf.go

示例15: loadKeyRing

func loadKeyRing(ringpath string) (openpgp.EntityList, error) {
	f, err := os.Open(ringpath)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	return openpgp.ReadKeyRing(f)
}
开发者ID:kubernetes,项目名称:helm,代码行数:8,代码来源:sign.go


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