本文整理匯總了Golang中github.com/cathalgarvey/go-minilock/taber.Keys.Encrypt方法的典型用法代碼示例。如果您正苦於以下問題:Golang Keys.Encrypt方法的具體用法?Golang Keys.Encrypt怎麽用?Golang Keys.Encrypt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cathalgarvey/go-minilock/taber.Keys
的用法示例。
在下文中一共展示了Keys.Encrypt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: EncryptDecryptInfo
// Encrypt a decryptInfo struct using the ephemeral pubkey and the same nonce as the enclosed fileInfo.
func EncryptDecryptInfo(di *DecryptInfoEntry, nonce []byte, ephemKey, recipientKey *taber.Keys) ([]byte, error) {
plain, err := json.Marshal(di)
if err != nil {
return nil, err
}
// NaClKeypair.Encrypt(plaintext, nonce []byte, to *NaClKeypair) (ciphertext []byte, err error)
di_enc, err := ephemKey.Encrypt(plain, nonce, recipientKey)
if err != nil {
return nil, err
}
return di_enc, nil
}
示例2: NewDecryptInfoEntry
func NewDecryptInfoEntry(nonce []byte, fileinfo *FileInfo, senderKey, recipientKey *taber.Keys) (*DecryptInfoEntry, error) {
encoded_fi, err := json.Marshal(fileinfo)
if err != nil {
return nil, err
}
cipher_fi, err := senderKey.Encrypt(encoded_fi, nonce, recipientKey)
if err != nil {
return nil, err
}
senderID, err := senderKey.EncodeID()
if err != nil {
return nil, err
}
recipientID, err := recipientKey.EncodeID()
if err != nil {
return nil, err
}
return &DecryptInfoEntry{SenderID: senderID, RecipientID: recipientID, FileInfoEnc: cipher_fi}, nil
}