Add API Metadata Encryption

This commit is contained in:
Samuel Lorch 2025-05-12 14:43:04 +02:00
parent d5f79a943f
commit b0a66d5dbf
2 changed files with 18 additions and 0 deletions

View file

@ -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)

View file

@ -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
}