本文整理匯總了Golang中github.com/keybase/go-triplesec.Cipher類的典型用法代碼示例。如果您正苦於以下問題:Golang Cipher類的具體用法?Golang Cipher怎麽用?Golang Cipher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Cipher類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ToServerSKB
func (key *PGPKeyBundle) ToServerSKB(gc *GlobalContext, tsec *triplesec.Cipher, gen PassphraseGeneration) (ret *SKB, err error) {
ret = NewSKB(gc)
var pk, sk bytes.Buffer
// Need to serialize Private first, because
err = key.Entity.SerializePrivate(&sk, nil)
if err != nil {
return
}
if tsec != nil {
ret.Priv.Data, err = tsec.Encrypt(sk.Bytes())
ret.Priv.Encryption = int(triplesec.Version) // Version 3 is the current TripleSec version
if err != nil {
return
}
} else {
ret.Priv.Data = sk.Bytes()
ret.Priv.Encryption = 0
}
ret.Priv.PassphraseGeneration = int(gen)
err = key.Entity.Serialize(&pk)
if err != nil {
return
}
ret.Pub = pk.Bytes()
ret.Type = key.GetAlgoType()
return
}
示例2: tsecUnlock
func (s *SKB) tsecUnlock(tsec *triplesec.Cipher) ([]byte, error) {
unlocked, err := tsec.Decrypt(s.Priv.Data)
if err != nil {
if _, ok := err.(triplesec.BadPassphraseError); ok {
err = PassphraseError{}
}
return nil, err
}
return unlocked, nil
}