mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-13 11:08:21 +00:00
Add API Metadata Encryption
This commit is contained in:
parent
d5f79a943f
commit
b0a66d5dbf
2 changed files with 18 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue