本文整理汇总了Golang中golang.org/x/crypto/openpgp.Entity.SerializePrivate方法的典型用法代码示例。如果您正苦于以下问题:Golang Entity.SerializePrivate方法的具体用法?Golang Entity.SerializePrivate怎么用?Golang Entity.SerializePrivate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/openpgp.Entity
的用法示例。
在下文中一共展示了Entity.SerializePrivate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: 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
}
示例3: 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
}