使用Rails凭据加密来加密文件

发布于 2025-02-04 08:45:28 字数 125 浏览 4 评论 0原文

我正在尝试在代码中使用Rails凭据加密。

我想通过将文件和加密密钥传递给文件来加密文件 方法。 我希望结果是可用的加密凭据文件。

不确定我是否可以按照我想要的Ruby代码中使用凭据加密,也不知道从哪里开始。

I'm trying to use Rails credentials encryption in the code.

I want to encrypt the file by passing the file with credentials and encryption key to the
method.
I want the result to be a usable encrypted credentials file.

Not sure if i can use credentials encryption in Ruby code as i would like to and i don't know where to start.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

信愁 2025-02-11 08:45:29

给定_path_/file_to_be_encrypted.txt作为加密文件:

encrypted = Rails.application.encrypted('_PATH_/file_to_be_encrypted.txt.enc')
encrypted.write(File.read('_PATH_/file_to_be_encrypted.txt'))

要读取加密文件:

Rails.application.encrypted('_PATH_/file_to_be_encrypted.txt.enc').read

Given _PATH_/file_to_be_encrypted.txt as the file to encrypt:

encrypted = Rails.application.encrypted('_PATH_/file_to_be_encrypted.txt.enc')
encrypted.write(File.read('_PATH_/file_to_be_encrypted.txt'))

To read encrypted file:

Rails.application.encrypted('_PATH_/file_to_be_encrypted.txt.enc').read
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文