Exemplo n.º 1
0
// DecryptBlob decrypts the given slice of data.
func (i *Ident) DecryptBlob(data []byte, publicKey *[crypto.PublicKeySize]byte, nonce *[crypto.NonceSize]byte) ([]byte, error) {
	sharedKey := crypto.PrecomputeKey(publicKey, i.SecretKey)
	decryptedData, err := crypto.Decrypt(data, sharedKey, nonce)
	if err != nil {
		return nil, err
	}

	return decryptedData, nil
}
Exemplo n.º 2
0
// EncryptBlob encrypts the given slice of data.
func (i *Ident) EncryptBlob(data []byte, publicKey *[crypto.PublicKeySize]byte) ([]byte, *[crypto.NonceSize]byte, error) {
	sharedKey := crypto.PrecomputeKey(publicKey, i.SecretKey)
	encryptedPayload, nonce, err := crypto.Encrypt(data, sharedKey)
	if err != nil {
		return nil, nil, err
	}

	return encryptedPayload, nonce, nil
}