简体   繁体   English

从 couchdb 返回 sha1() hash

[英]Return sha1() hash from couchdb

I have some data stored in CouchDb of the form key-value .我有一些数据以key-value形式存储在 CouchDb 中。 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.我创建了一个视图,该视图返回这些元组并使用 javascript 在客户端计算+ salt的 sha1()。 Is it possible to send the sha1() hash of value + salt directly from CouchDb as JSON?是否可以直接从 CouchDb 作为 JSON 发送价值+的 sha1() hash? I do not wish to send the salt to the client.我不希望将盐发送给客户。 Thanks.谢谢。

I suggest a Javascript SHA1 [1] implementation directly on CouchDB.我建议直接在 CouchDB 上实现 Javascript SHA1 [1]。 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.计算_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 . CouchDB 中有一个 SHA1 Javascript 实现,将您的浏览器指向您的 Couch 服务器,位于/_utils/script/sha1.js中。 You can copy and paste the code if you want.如果需要,您可以复制并粘贴代码。

[1] Or consider SHA256 or SHA512 if possible. [1] 或者尽可能考虑 SHA256 或 SHA512。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM