Created
April 28, 2024 06:07
-
-
Save pmatsinopoulos/de998768d92759aa67d46a8632db3425 to your computer and use it in GitHub Desktop.
Encrypt a file using RoR Utilities
This file contains hidden or 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') | |
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