
[英]Rails: ActiveSupport::MessageEncryptor::InvalidMessage
[英]Rails decrypt goes wrong with MessageEncryptor::InvalidMessage
我的 rails 5.2.4.2 应用程序(开发环境)中有以下情况:
文件:chiffres_controller.rb
def encrypt text
text = text.to_s unless text.is_a? String
len = ActiveSupport::MessageEncryptor.key_len
salt = SecureRandom.hex len
key = ActiveSupport::KeyGenerator.new(Rails.application.credentials.secret_key_base).generate_key(salt, len)
crypt = ActiveSupport::MessageEncryptor.new key
encrypted_data = crypt.encrypt_and_sign text
"#{salt}$$#{encrypted_data}"
end
def decrypt text
salt, data = text.split "$$"
len = ActiveSupport::MessageEncryptor.key_len
key = ActiveSupport::KeyGenerator.new(Rails.application.credentials.secret_key_base).generate_key(salt, len)
crypt = ActiveSupport::MessageEncryptor.new key
crypt.decrypt_and_verify data
end
这用于显示或隐藏我的仅包含数字的秘密字符串。 重新启动后它一直工作到今天。 最后的变化是使用这些方法的 rufus-scheduler 的新调度程序实例。 然后我收到以下消息:
ActionView::Template::Error (ActiveSupport::MessageEncryptor::InvalidMessage):
22: <% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(block) %>
23: <% capture_haml(day, sorted_events.fetch(day, []), &block) %>
24: <% else %>
25: <% block.call day, sorted_events.fetch(day, []) %>
26: <% end %>
27: <% end %>
28: <% end %>
app/controllers/chiffres_controller.rb:157:in `decrypt'
app/views/presences/index.html.erb:26:in `block (2 levels) in _app_views_presences_index_html_erb__473195322_124069440'
app/views/presences/index.html.erb:24:in `each'
app/views/presences/index.html.erb:24:in `block in _app_views_presences_index_html_erb__473195322_124069440'
app/views/presences/index.html.erb:20:in `_app_views_presences_index_html_erb__473195322_124069440'
第 157 行如下: crypt.decrypt_and_verify data
我的 index.html.rb 看起来像(第 20 - 26 行):
<%= calendar number_of_days: 1, events: @meetings do |date, meetings| %>
<div style="width: 100%"><%= date.strftime("%d.%m.%Y") %> <%= link_to "Coronaliste (xlsx)", corona_path(format: "xlsx", :date => date) %></div>
<br/>
<% if meetings.present? %>
<% meetings.each do |met| %>
<% if met.place_id != 20 %>
<% @theres[@ch.decrypt(met.secret).to_i] = "i" %>
我已经读过我应该像这里一样重新生成我的master.key和credentials.yml.enc 。 我这样做了,但没有任何改变。 我正在 Windows 10 机器上工作,但我不知道为什么会发生这种情况。 我需要修复,以便我可以再次读取我的秘密数据(数字)。 任何帮助表示赞赏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.