From b0a66d5dbfa5beace6d57e602e3a61e1ac95e7ed Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Mon, 12 May 2025 14:43:04 +0200 Subject: [PATCH] Add API Metadata Encryption --- api/encryption.go | 7 +++++++ api/metadata.go | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/api/encryption.go b/api/encryption.go index c39eee3..2c393ee 100644 --- a/api/encryption.go +++ b/api/encryption.go @@ -33,12 +33,19 @@ func (c *Client) EncryptMessage(message string) (string, error) { } // EncryptMessageWithPublicKey encrypts a message using the provided public key and then signes the message using the users private key +// +// Deprecated: EncryptMessageWithPublicKey is deprecated. Use EncryptMessageWithKey instead func (c *Client) EncryptMessageWithPublicKey(publickey, message string) (string, error) { publicKey, err := crypto.NewKeyFromArmored(publickey) if err != nil { return "", fmt.Errorf("Get Public Key: %w", err) } + return c.EncryptMessageWithKey(publicKey, message) +} + +// EncryptMessageWithKey encrypts a message using the provided key and then signes the message using the users private key +func (c *Client) EncryptMessageWithKey(publicKey *crypto.Key, message string) (string, error) { key, err := c.userPrivateKey.Copy() if err != nil { return "", fmt.Errorf("Get Private Key Copy: %w", err) diff --git a/api/metadata.go b/api/metadata.go index f62464f..cc40425 100644 --- a/api/metadata.go +++ b/api/metadata.go @@ -68,3 +68,14 @@ func (c *Client) DecryptMetadata(metadataKey *crypto.Key, armoredCiphertext stri return metadata, nil } + +func (c *Client) EncryptMetadata(metadataKey *crypto.Key, data string) (string, error) { + armoredCiphertext, err := c.EncryptMessageWithKey(metadataKey, data) + if err != nil { + return "", fmt.Errorf("Encrypting Metadata: %w", err) + } + + // TODO save Session Key to cache + + return armoredCiphertext, nil +}