Some time ago I created a gem adding encrypted attributes to relations using custom types. It is designed to be compatible with ActiveRecord encryption, in case you’re moving from ActiveRecord-powered database to ROM. For now quite a few features from ActiveRecord::Encryption
are missing, but basic stuff is working and I think it can already be used.
Here’s a link to the repo: GitHub - katafrakt/rom_encrypted_attribute: RomEncryptedAttribute: Rails-compatible encrypted attributes for ROM
Example usage:
class SecretNotes < ROM::Relation[:sql]
EncryptedString, EncryptedStringReader =
RomEncryptedAttribute.define_encrypted_attribute_types(
primary_key: ENV["ENCRYPTION_PRIMARY_KEY"],
key_derivation_salt: ENV["ENCRYPTION_KEY_DERIVATION_SALT"]
)
schema(:secret_notes, infer: true) do
attribute :content, EncryptedString, read: EncryptedStringReader
end
end
Looking for feedback. Thanks!