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?
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
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With