本文整理匯總了Golang中code/google/com/p/go/crypto/openpgp.Entity類的典型用法代碼示例。如果您正苦於以下問題:Golang Entity類的具體用法?Golang Entity怎麽用?Golang Entity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Entity類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SerializeKeys
func SerializeKeys(entity *openpgp.Entity) (privKeyArmor, pubKeyArmor string, err error) {
// First serialize the private parts.
// NOTE: need to call this in order to initialize the newly created entities,
// otherwise entity.Serialize() will fail
// https://code.google.com/p/go/issues/detail?id=6483
b := bytes.NewBuffer(nil)
w, _ := armor.Encode(b, openpgp.PrivateKeyType, nil)
err = entity.SerializePrivate(w, nil)
if err != nil {
return "", "", err
}
w.Close()
privKeyArmor = b.String()
// Serialize the public key.
b.Reset()
w, _ = armor.Encode(b, openpgp.PublicKeyType, nil)
err = entity.Serialize(w)
if err != nil {
return "", "", err
}
w.Close()
pubKeyArmor = b.String()
return
}
示例2: PubEntToAsciiArmor
//PubEntToAsciiArmor creates ASscii Armor from pubEnt of type openpgp.Entity
func PubEntToAsciiArmor(pubEnt openpgp.Entity) (asciiEntity string, err error) {
gotWriter := bytes.NewBuffer(nil)
wr, errEncode := armor.Encode(gotWriter, openpgp.PublicKeyType, nil)
if errEncode != nil {
// fmt.Println("Encoding Armor ", errEncode.Error())
err = errEncode
return
}
errSerial := pubEnt.Serialize(wr)
if errSerial != nil {
// fmt.Println("Serializing PubKey ", errSerial.Error())
}
errClosing := wr.Close()
if errClosing != nil {
// fmt.Println("Closing writer ", errClosing.Error())
}
asciiEntity = gotWriter.String()
return
}
示例3: AddPublicKey
func AddPublicKey(e *openpgp.Entity) error {
return serializeKey(e, publicKeyringFilename, func(w io.Writer) error {
return e.Serialize(w)
})
}
示例4: addSecretKey
func addSecretKey(e *openpgp.Entity) error {
return serializeKey(e, secretKeyringFilename, func(w io.Writer) error {
return e.SerializePrivate(w, nil)
})
}
示例5: ArmorSecretKey
func ArmorSecretKey(e *openpgp.Entity) (string, error) {
return exportArmoredKey(e, secretKeyArmorHeader, func(w io.Writer) error {
return e.SerializePrivate(w, nil)
})
}
示例6: ArmorPublicKey
func ArmorPublicKey(e *openpgp.Entity) (string, error) {
return exportArmoredKey(e, publicKeyArmorHeader, func(w io.Writer) error {
return e.Serialize(w)
})
}