Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the CouchDB attachment's md5 digest format?

Tags:

md5

couchdb

I'm trying to use the md5 digest of an attachment I put on the CouchDB, but I can't understand 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 do I use it?

like image 670
Federico Bonelli Avatar asked Dec 21 '12 12:12

Federico Bonelli


2 Answers

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

If parsing in Javascript, the atob function can turn it back into binary data.

Assuming the above is correct then the hexadecimal equivalent is:

c8 36 ec d6 c7 1f 61 da aa 2e 9c 72 15 bd 60 17
like image 124
Alnitak Avatar answered Nov 02 '22 15:11

Alnitak


For anyone looking to work with the digest format used by couchdb using nodejs you can turn the base64 encoded digest into a "normal" hex string by removing the "md5-" prefix and then do:

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

To go the other way and create the digest string from a hex value:

new Buffer('c836ecd6c71f61daaa2e9c7215bd6017', 'hex').toString('base64')
like image 2
gabrielf Avatar answered Nov 02 '22 15:11

gabrielf