Skip to content

Instantly share code, notes, and snippets.

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