Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 using 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.

like image 511
Vipin Parakkat Avatar asked Jul 06 '11 08:07

Vipin Parakkat


1 Answers

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.

like image 53
JasonSmith Avatar answered Nov 12 '22 15:11

JasonSmith