开发者

SHA1 hashing in Rails

开发者_高级运维

I have database with following fields: id, q_id, text, session etc. and I have already 2 records there. I want to hash each line with SHA1 alghoritm (every line is unique of course). I tried this:

@w = Digest::SHA1.hexdigest(id+q_id+text+session)

but it doesn't work.


SHA is not encryption but rather it creates a cryptographic hash. If that is still what you want to do, my guess is that id and q_id are Fixnums and needs to be converted to strings.

@w = Digest::SHA1.hexdigest(ans.id.to_s + ans.q_id.to_s + ans.text + ans.session)

I also kind of like to use String literals because it makes it very obvious that we are dealing with a string

@w = Digest::SHA1.hexdigest("#{id}#{q_id}#{text}#{session}")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜