开发者

rails 3.0 encryption strongbox

开发者 https://www.devze.com 2023-03-12 08:48 出处:网络
In the context of rails 3.0 project, a database field must be encrypted. gem Strongbox is used for managing the encryption. The implementation follows the readme on github (see link).

In the context of rails 3.0 project, a database field must be encrypted. gem Strongbox is used for managing the encryption. The implementation follows the readme on github (see link). The issue is that the view throws an error:

invalid byte sequence in UTF-8

for <%= f.text_field :my_field %>

Is there anything special to be done to 开发者_如何学Goget the field decrypted on the view?


The documentation for Strongbox states: "In your views and forms you don’t need to do anything special to encrypt data. To decrypt call: user.secret.decrypt 'password'"

The Rails form builder does not call decrypt on the value when generating the form so that is why you will get this error. You have two alternatives:

  • Set the text_field value manually for all encrypted fields, e.g.

    '<%= f.text_field :my_field, :value => user.my_field.decrypt "password" %>'

  • Build a custom form generator that decrypts encrypted values when generating the form.

0

精彩评论

暂无评论...
验证码 换一张
取 消