为什么使用 Ruby 将 AES 加密字符串保存到 MySQL 表中时为空?
我有一个名为 Encryption 的模型,它生成 AES 加密字符串并将其保存到名为“加密”的数据库表中。我的加密表架构如下:
id : bigint unsigned
user_id : bigint unsigned
encryption : VARCHAR(128) (utf8_unicode_ci)
created_at : datetime
updated_at : datetime
但是,当我在加密模型实例上调用 .save 时,encryption.encryption(在数据库中)的值为空 ('')。
这是模型的内容:
ruby-1.9.2-head :005 > encryption
=> #<Encryption id: nil, user_id: 1, encryption: "\xD6\xD6\x95\x15\x0F\x92\xC6\x01\x86\x1E\x88\xD1\xB0\x1D\xE0\xEC", created_at: nil, updated_at: nil>
正如您所看到的,它在模型中确实具有值。关于为什么该字段在数据库中保存为空白的任何想法?
I have a model called Encryption which generates an AES encrypted string and saves that to a database table called encryptions. My encryption table schema is as follows:
id : bigint unsigned
user_id : bigint unsigned
encryption : VARCHAR(128) (utf8_unicode_ci)
created_at : datetime
updated_at : datetime
However, when I call .save on my encryption model instance, the value for encryption.encryption (in the database) is blank ('').
Here's the contents of the model:
ruby-1.9.2-head :005 > encryption
=> #<Encryption id: nil, user_id: 1, encryption: "\xD6\xD6\x95\x15\x0F\x92\xC6\x01\x86\x1E\x88\xD1\xB0\x1D\xE0\xEC", created_at: nil, updated_at: nil>
As you can see, it does have a value in the model. Any ideas on why the field is saving as blank in the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在使用保险箱 gem 来做类似的事情,它要求列类型为
:binary
,而不是文本,也许你可以尝试一下......I'm using the strongbox gem to do something similar, and it requested a column type of
:binary
, not text, maybe you could try that...您似乎将字符串保存到 bigint 列中,这是行不通的。将其切换为文本列类型。
You appear to be saving a string into a bigint column, which won't work. Switch it to a text column type.