开发者

Return sha1() hash from couchdb

开发者 https://www.devze.com 2023-03-17 20:04 出处:网络
I have some data stored in CouchDb of the form key-value. Basically it a tuple with a value and salt. I have created a view that return these tuples and calculate the sha1() of the value + salt on the

I have some data stored in CouchDb of the form key-value. Basically it a tuple with a value and salt. I have created a view that return these tuples and calculate the sha1() of the value + salt on the client side u开发者_JS百科sing javascript. Is it possible to send the sha1() hash of value + salt directly from CouchDb as JSON? I do not wish to send the salt to the client. Thanks.


I suggest a Javascript SHA1 [1] implementation directly on CouchDB. I think you have two options:

  1. Compute the checksum in the view. Query speed will be unchanged, but the view code will grow a bit.
  2. Compute the checksum in a _list function. Query speed will be (in principle) slower, since you execute code for every row for every query; but your views can remain simple.

There is an SHA1 Javascript implementation in CouchDB! Point your browser to your Couch server, in /_utils/script/sha1.js. You can copy and paste the code if you want.

[1] Or consider SHA256 or SHA512 if possible.

0

精彩评论

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

关注公众号