What is the md5 digest format in CouchDB?

I am trying to use the attachment md5 digest that I put in CouchDB, but I cannot figure out what format it uses.

{ "_id":"ef467479af422db0c388fa00b3000d40", "_rev":"3-6d1015e7d25103180817136eefa9f942", "_attachments":{ "foo":{ "content_type":"application/octet-stream", "revpos":2, "digest":"md5-yDbs1scfYdqqLpxyFb1gFw==", "length":1952913,"stub":true } } } 

That md5 is not hexadecimal, but still it is ASCII, how to use it?

+6
source share
2 answers

The part of the digest after the md5- prefix looks like in Base-64 format.

If parsing in Javascript, the atob function can return it back to binary data.

Assuming the above is correct, the hexadecimal equivalent is:

 c8 36 ec d6 c7 1f 61 da aa 2e 9c 72 15 bd 60 17 
+7
source

For those who want to work with the digest format used by couchdb using nodejs, you can turn the base64 encoded digest into a β€œnormal” sixth line by removing the β€œmd5-” prefix, and then do:

 new Buffer('yDbs1scfYdqqLpxyFb1gFw==', 'base64').toString('hex') 

To jump in another way and create a digest string from a hex value:

 new Buffer('c836ecd6c71f61daaa2e9c7215bd6017', 'hex').toString('base64') 
0
source

All Articles