Encrypt

An Encrypt operation is the process of converting confidential data from a plaintext value to an unreadable version. An encrypted value is referred to as ciphertext. This operation uses a Crypto Key as defined by a keySpec.

type Encrypt struct {
    KeySpec *KeySpec `json:"key_spec,omitempty"`
}

type KeySpec struct {
    // Example = arn:aws:kms:us-west-2:436578702069:key/f5208fa1-13f1-4d9c-90e8-802609342d07
    Selector string `json:"selector"`
    // Example = low
    SensivityLevel string `json:"sensitivity_level"
}
import (
    "reflect"
    "github.com/ume/api/pkg/mirror"
)

func HandleFormSubmission(form *Form) {
    // form = {name: Ada}
    formData := form.ToMap()
    envelope := mirror.Envelope{
        Data: formData,
        Operations: []mirror.Operation{
            {
                DataLocation: mirror.DataLocation{
                    Source: "name",
                    Destination: "enc_name",
                },
                Encrypt: &mirror.Encrypt{},
            },
        },
    }

    envelope.Execute()

    if assertNotEqual(envelope.Data["name"], envelope.Data["enc_name"]) {
        // Name was successfully encrypted
    }
}

func assertNotEqual(expected, actual interface{}) bool {
    isEqual := reflect.DeepEqual(expected, actual)

    return !isEqual
}

Before

{
  "data": { "name": "Ada" },
  "ops": [{ "src": "name", "dest": "enc_name", "encrypt": {} }]
}

After

{
  "data": {
    "name": "Ada",
    "enc_name": "8J-c902frj3vm2sicz"
  },
  "ops": []
}