Return sha1() hash from couchdb
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:
- Compute the checksum in the view. Query speed will be unchanged, but the view code will grow a bit.
- 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.
精彩评论