Exemple #1
0
// 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
}
Exemple #2
0
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
}