本文整理汇总了Golang中golang.org/x/crypto/openpgp.ReadKeyRing函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadKeyRing函数的具体用法?Golang ReadKeyRing怎么用?Golang ReadKeyRing使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadKeyRing函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: decryptOpenpgp
func decryptOpenpgp(data io.Reader, gpghome string, pass []byte) (io.Reader, error) {
privkeyfile, err := os.Open(fmt.Sprintf("%s%ssecring.gpg", gpghome, string(os.PathSeparator)))
if err != nil {
fmt.Println("Failed to open secring", err)
return nil, err
}
privring, err := openpgp.ReadKeyRing(privkeyfile)
if err != nil {
fmt.Println("Failed to open secring", err)
return nil, err
}
//reader := bytes.NewReader(data)
//brk,_ := ioutil.ReadAll(data)
//fmt.Println("wtf",string(brk))
//fmt.Println("here is where eof panic")
block, err := armor.Decode(data)
if err != nil {
fmt.Println(err)
panic(err)
}
if len(pass) == 0 {
fmt.Fprintf(os.Stderr, "Password: ")
pass, err = terminal.ReadPassword(0)
if err != nil {
panic(err)
}
fmt.Fprintln(os.Stderr, "")
}
for _, entity := range privring {
if entity.PrivateKey != nil && entity.PrivateKey.Encrypted {
entity.PrivateKey.Decrypt(pass)
}
for _, subkey := range entity.Subkeys {
if subkey.PrivateKey != nil && subkey.PrivateKey.Encrypted {
subkey.PrivateKey.Decrypt(pass)
}
}
}
md, err := openpgp.ReadMessage(block.Body, privring, nil, nil)
if err != nil {
return nil, err
}
return md.UnverifiedBody, nil
//plaintext, err := ioutil.ReadAll(md.UnverifiedBody)
//if err != nil {
// panic(err)
// }
// return plaintext, nil
}
开发者ID:jamesunger,项目名称:ipboh,代码行数:57,代码来源:ipboh.go
示例17: Fuzz
func Fuzz(data []byte) int {
r := bytes.NewBuffer(data)
_, err := openpgp.ReadKeyRing(r)
if err != nil {
return 0
}
return 1
}
开发者ID:marete,项目名称:gofuzz,代码行数:10,代码来源:main.go
示例18: KeyRing
// KeyRing reads a openpgp.KeyRing from the given io.Reader which may then be
// used to validate GPG keys in RPM packages.
func KeyRing(r io.Reader) (openpgp.KeyRing, error) {
// decode gpgkey file
p, err := armor.Decode(r)
if err != nil {
return nil, err
}
// extract keys
return openpgp.ReadKeyRing(p.Body)
}
开发者ID:tjyang,项目名称:go-rpm,代码行数:12,代码来源:keyring.go
示例19: loadRing
func (key *MasterKey) loadRing(path string) (openpgp.EntityList, error) {
f, err := os.Open(path)
if err != nil {
return openpgp.EntityList{}, err
}
defer f.Close()
keyring, err := openpgp.ReadKeyRing(f)
if err != nil {
return keyring, err
}
return keyring, nil
}
开发者ID:twolfson,项目名称:sops,代码行数:12,代码来源:keysource.go
示例20: GetEntityFrom
// GetEntityFrom returns (OpenPGP) Entity values for the specified
// user's private or public key (from secring.gpg or pubring.gpg,
// respectively)
func GetEntityFrom(emailOrName, sourceFile string) (*openpgp.Entity, error) {
// Default case: sourceFile == PUBLIC_KEYRING_FILENAME
keyType := "public"
keyMap := pubkeys
if sourceFile == PRIVATE_KEYRING_FILENAME {
keyType = "private"
keyMap = privkeys
}
if key, ok := pubkeys[emailOrName]; ok {
if DEBUG {
log.Printf("Grabbed cached pubkey for %s\n", emailOrName)
}
return key, nil
}
ringFile, err := os.Open(sourceFile)
if err != nil {
return nil, fmt.Errorf("Error opening %s key file %s: %v",
keyType, sourceFile, err)
}
defer ringFile.Close()
ring, err := openpgp.ReadKeyRing(ringFile)
if err != nil {
return nil, fmt.Errorf("Error reading %s key file %s: %v",
keyType, sourceFile, err)
}
if DEBUG {
log.Printf("Grabbed %s key for %s off disk\n", keyType, emailOrName)
}
key := GetKeyByEmail(ring, emailOrName)
if key == nil {
key = GetKeyByName(ring, emailOrName)
}
if key == nil {
e := fmt.Errorf("Couldn't find key for user %s: %v", emailOrName, err)
return nil, e
}
// TODO: Is adding to this map this thread safe? Doesn't look
// like it. Should it be?
keyMap[emailOrName] = key
return key, nil
if sourceFile != PUBLIC_KEYRING_FILENAME && sourceFile != PRIVATE_KEYRING_FILENAME {
panic("GetEntityFrom: Asking for neither private nor public key???")
}
return nil, fmt.Errorf("This should never happen!!!\n")
}
开发者ID:thecloakproject,项目名称:utils,代码行数:55,代码来源:gpg.go
注:本文中的golang.org/x/crypto/openpgp.ReadKeyRing函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论