Created
April 28, 2024 06:12
-
-
Save pmatsinopoulos/2311b9085de6cab2c1be201020e08f1a to your computer and use it in GitHub Desktop.
Encrypt a file using RoR Utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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