Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pmatsinopoulos/de998768d92759aa67d46a8632db3425 to your computer and use it in GitHub Desktop.
Save pmatsinopoulos/de998768d92759aa67d46a8632db3425 to your computer and use it in GitHub Desktop.
Encrypt a file using RoR Utilities
content_path = Rails.root.join('secret_content_file.txt')
encrypted_file = ActiveSupport::EncryptedFile.new(
content_path: "#{content_path}.enc",
key_path: Rails.application.config.credentials.key_path,
env_key: "RAILS_MASTER_KEY",
raise_if_missing_key: true
)
contents = File.read(content_path)
encrypted_file.write(contents)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment