You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Moritz Post <mp...@eclipsesource.com> on 2011/09/27 15:29:50 UTC

Create Content-MD5 hash

Hallo CouchDB

I am trying to validate the integrity of data i upload to the couchdb.
Therefore i provide a valid MD5 hash alongside my PUT request. From what i
have gathered this md5 has to be base64 encoded. My problem is that i am not
able to create a valid hash. All i get is:

{"error":"content_md5_mismatch","reason":"Possible message corruption."}

I am currently experimenting with a CURL based approach but will need
to incorporate the hash creation into a java program later. Here is what is
did do create the md5 hash:

$ md5sum test.json
4bf3aac171ded1679d3501ccbd3e0d85  test.json
$ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK

So i have a hash value and now use it in my PUT request (verbose output):

$ curl -X PUT -H "Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
-H "Content-Type: application/json" -v -d @test.json
http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
* About to connect() to 192.168.6.168 port 5984 (#0)
*   Trying 192.168.6.168... connected
* Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
* Server auth using Basic with user 'admin'
> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb HTTP/1.1
> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o
zlib/1.2.3.4 libidn/1.18
> Host: 192.168.6.168:5984
> Accept: */*
> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> Content-Type: application/json
> Content-Length: 19
>
< HTTP/1.1 400 Bad Request
< Server: CouchDB/1.0.2 (Erlang OTP/R14B)
< Date: Tue, 27 Sep 2011 13:23:38 GMT
< Content-Type: text/plain;charset=utf-8
< Content-Length: 73
< Cache-Control: must-revalidate
<
{"error":"content_md5_mismatch","reason":"Possible message corruption."}
* Connection #0 to host 192.168.6.168 left intact
* Closing connection #0

I am running a couchdb 1.0.3.

The question is: how to properly create a md5 hash that validates the
upload.

Additionally i would like to know if it is only possible to validated
attachment uploads or is it also possible to validated the uploaded json
documents one creates in the couchdb?

Thank you
Moritz Post

-- 
-----------------------------------
Moritz Post
EclipseSource
Email: mpost@eclipsesource.com
Tel: +49-721-66-47-33-33
Fax: +49-721-66-47-33-29
http://www.eclipsesource.com/
========================= Legal Disclaimer =================================
According to Section 80 of the German Corporation Act
Innoopract Informationssysteme GmbH must indicate the following information:
Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
General Manager: Jochen Krause
Registered Office: Commercial Register Mannheim HRB 107883
============================================================================

Re: Create Content-MD5 hash

Posted by Moritz Post <mp...@eclipsesource.com>.
Hi Robert

Ok, thanks for clarifying.

Regards
Moritz Post

On Wed, Sep 28, 2011 at 12:00 AM, Robert Newson <rn...@apache.org> wrote:

> I'm pretty sure MD5 verification is only available for standalone
> attachments right now.
>
> B.
>
> On 27 September 2011 18:32, Moritz Post <mp...@eclipsesource.com> wrote:
> > Hi Robert
> >
> > No problem. The issue has been solved. So how about validating newly
> created
> > documents?
> >
> > Greets
> > Moritz
> >
> > On Tue, Sep 27, 2011 at 5:52 PM, Robert Newson <rn...@apache.org>
> wrote:
> >
> >> Heh, I totally missed that you hadn't converted to hex in the middle,
> >> sorry.
> >>
> >> On 27 September 2011 16:18, Moritz Post <mp...@eclipsesource.com>
> wrote:
> >> > Hi Keith
> >> >
> >> > Thanks for the hint. I have actually applied it onto a java
> >> implementation
> >> > of the hash generation and it produced a correct hash value. Here is
> my
> >> > implementation:
> >> >
> >> > MessageDigest md5 = MessageDigest.getInstance("MD5");
> >> > byte[] digest = md5.digest("{ \"valid\": \"json\" }".getBytes());
> >> > byte[] hash = Base64.encodeBase64(digest);
> >> > System.out.println(new String(hash));
> >> >
> >> > Output: S/OqwXHe0WedNQHMvT4NhQ==
> >> >
> >> > It uses Base64 from the apache commons project. I have used that has
> >> value
> >> >
> >> > Now onto my final question: can i also validated the content of a
> couchdb
> >> > document i create by uploading a json document?
> >> >
> >> > Regards
> >> > Moritz Post
> >> >
> >> > On Tue, Sep 27, 2011 at 4:57 PM, Keith Gable <
> ziggy@ignition-project.com
> >> >wrote:
> >> >
> >> >> According to RFC2616 (
> >> >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html),
> >> >> section 14.15, you need the Base64 encoding of the actual MD5 bits,
> not
> >> the
> >> >> base64 encoding of the hex encoding of MD5 bits.
> >> >>
> >> >> In Ruby, after you require the base64 and digest/md5 libraries, you
> can
> >> >> generate a Base64 of the raw bits by doing this:
> >> >>
> >> >> Base64.encode64(Digest::MD5.digest(your_file_iostream))
> >> >>
> >> >>
> >> >> Hope that helps.
> >> >>
> >> >> ---
> >> >> Keith Gable
> >> >> A+ Certified Professional
> >> >> Network+ Certified Professional
> >> >> Web Developer
> >> >>
> >> >>
> >> >>
> >> >> On Tue, Sep 27, 2011 at 9:47 AM, Moritz Post <
> mpost@eclipsesource.com
> >> >> >wrote:
> >> >>
> >> >> > Hi Robert
> >> >> >
> >> >> > Thanks for the reply. Using -n does produce a different echo output
> >> but
> >> >> it
> >> >> > does not produce a hash consumable by the couchdb:
> >> >> >
> >> >> > $ echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >> >> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODU=
> >> >> >
> >> >> > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >> >> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >> >> >
> >> >> > Using the hash with the = at the end i still get the response:
> >> >> > {"error":"content_md5_mismatch","reason":"Possible message
> >> corruption."}
> >> >> >
> >> >> > Greets
> >> >> > Moritz
> >> >> >
> >> >> > On Tue, Sep 27, 2011 at 4:19 PM, Robert Newson <rnewson@apache.org
> >
> >> >> wrote:
> >> >> >
> >> >> > > try
> >> >> > >
> >> >> > > echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >> >> > >
> >> >> > > as echo includes a new line unless you use -n.
> >> >> > >
> >> >> > > B.
> >> >> > >
> >> >> > > On 27 September 2011 14:29, Moritz Post <mpost@eclipsesource.com
> >
> >> >> wrote:
> >> >> > > > Hallo CouchDB
> >> >> > > >
> >> >> > > > I am trying to validate the integrity of data i upload to the
> >> >> couchdb.
> >> >> > > > Therefore i provide a valid MD5 hash alongside my PUT request.
> >> From
> >> >> > what
> >> >> > > i
> >> >> > > > have gathered this md5 has to be base64 encoded. My problem is
> >> that i
> >> >> > am
> >> >> > > not
> >> >> > > > able to create a valid hash. All i get is:
> >> >> > > >
> >> >> > > > {"error":"content_md5_mismatch","reason":"Possible message
> >> >> > corruption."}
> >> >> > > >
> >> >> > > > I am currently experimenting with a CURL based approach but
> will
> >> need
> >> >> > > > to incorporate the hash creation into a java program later.
> Here
> >> is
> >> >> > what
> >> >> > > is
> >> >> > > > did do create the md5 hash:
> >> >> > > >
> >> >> > > > $ md5sum test.json
> >> >> > > > 4bf3aac171ded1679d3501ccbd3e0d85  test.json
> >> >> > > > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >> >> > > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >> >> > > >
> >> >> > > > So i have a hash value and now use it in my PUT request
> (verbose
> >> >> > output):
> >> >> > > >
> >> >> > > > $ curl -X PUT -H "Content-MD5:
> >> >> > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
> >> >> > > > -H "Content-Type: application/json" -v -d @test.json
> >> >> > > >
> >> >> > >
> >> >> >
> >> >>
> >>
> http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> >> >> > > > * About to connect() to 192.168.6.168 port 5984 (#0)
> >> >> > > > *   Trying 192.168.6.168... connected
> >> >> > > > * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
> >> >> > > > * Server auth using Basic with user 'admin'
> >> >> > > >> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> >> >> > HTTP/1.1
> >> >> > > >> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3
> >> >> > > OpenSSL/0.9.8o
> >> >> > > > zlib/1.2.3.4 libidn/1.18
> >> >> > > >> Host: 192.168.6.168:5984
> >> >> > > >> Accept: */*
> >> >> > > >> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >> >> > > >> Content-Type: application/json
> >> >> > > >> Content-Length: 19
> >> >> > > >>
> >> >> > > > < HTTP/1.1 400 Bad Request
> >> >> > > > < Server: CouchDB/1.0.2 (Erlang OTP/R14B)
> >> >> > > > < Date: Tue, 27 Sep 2011 13:23:38 GMT
> >> >> > > > < Content-Type: text/plain;charset=utf-8
> >> >> > > > < Content-Length: 73
> >> >> > > > < Cache-Control: must-revalidate
> >> >> > > > <
> >> >> > > > {"error":"content_md5_mismatch","reason":"Possible message
> >> >> > corruption."}
> >> >> > > > * Connection #0 to host 192.168.6.168 left intact
> >> >> > > > * Closing connection #0
> >> >> > > >
> >> >> > > > I am running a couchdb 1.0.3.
> >> >> > > >
> >> >> > > > The question is: how to properly create a md5 hash that
> validates
> >> the
> >> >> > > > upload.
> >> >> > > >
> >> >> > > > Additionally i would like to know if it is only possible to
> >> validated
> >> >> > > > attachment uploads or is it also possible to validated the
> >> uploaded
> >> >> > json
> >> >> > > > documents one creates in the couchdb?
> >> >> > > >
> >> >> > > > Thank you
> >> >> > > > Moritz Post
> >> >> > > >
> >> >> > > > --
> >> >> > > > -----------------------------------
> >> >> > > > Moritz Post
> >> >> > > > EclipseSource
> >> >> > > > Email: mpost@eclipsesource.com
> >> >> > > > Tel: +49-721-66-47-33-33
> >> >> > > > Fax: +49-721-66-47-33-29
> >> >> > > > http://www.eclipsesource.com/
> >> >> > > > ========================= Legal Disclaimer
> >> >> > > =================================
> >> >> > > > According to Section 80 of the German Corporation Act
> >> >> > > > Innoopract Informationssysteme GmbH must indicate the following
> >> >> > > information:
> >> >> > > > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> >> >> > > > General Manager: Jochen Krause
> >> >> > > > Registered Office: Commercial Register Mannheim HRB 107883
> >> >> > > >
> >> >> > >
> >> >> >
> >> >>
> >>
> ============================================================================
> >> >> > > >
> >> >> > >
> >> >> >
> >> >> >
> >> >> >
> >> >> > --
> >> >> > -----------------------------------
> >> >> > Moritz Post
> >> >> > EclipseSource
> >> >> > Email: mpost@eclipsesource.com
> >> >> > Tel: +49-721-66-47-33-33
> >> >> > Fax: +49-721-66-47-33-29
> >> >> > http://www.eclipsesource.com/
> >> >> > ========================= Legal Disclaimer
> >> >> > =================================
> >> >> > According to Section 80 of the German Corporation Act
> >> >> > Innoopract Informationssysteme GmbH must indicate the following
> >> >> > information:
> >> >> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> >> >> > General Manager: Jochen Krause
> >> >> > Registered Office: Commercial Register Mannheim HRB 107883
> >> >> >
> >> >> >
> >> >>
> >>
> ============================================================================
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > -----------------------------------
> >> > Moritz Post
> >> > EclipseSource
> >> > Email: mpost@eclipsesource.com
> >> > Tel: +49-721-66-47-33-33
> >> > Fax: +49-721-66-47-33-29
> >> > http://www.eclipsesource.com/
> >> > ========================= Legal Disclaimer
> >> =================================
> >> > According to Section 80 of the German Corporation Act
> >> > Innoopract Informationssysteme GmbH must indicate the following
> >> information:
> >> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> >> > General Manager: Jochen Krause
> >> > Registered Office: Commercial Register Mannheim HRB 107883
> >> >
> >>
> ============================================================================
> >> >
> >>
> >
> >
> >
> > --
> > -----------------------------------
> > Moritz Post
> > EclipseSource
> > Email: mpost@eclipsesource.com
> > Tel: +49-721-66-47-33-33
> > Fax: +49-721-66-47-33-29
> > http://www.eclipsesource.com/
> > ========================= Legal Disclaimer
> =================================
> > According to Section 80 of the German Corporation Act
> > Innoopract Informationssysteme GmbH must indicate the following
> information:
> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> > General Manager: Jochen Krause
> > Registered Office: Commercial Register Mannheim HRB 107883
> >
> ============================================================================
> >
>



-- 
-----------------------------------
Moritz Post
EclipseSource
Email: mpost@eclipsesource.com
Tel: +49-721-66-47-33-33
Fax: +49-721-66-47-33-29
http://www.eclipsesource.com/
========================= Legal Disclaimer =================================
According to Section 80 of the German Corporation Act
Innoopract Informationssysteme GmbH must indicate the following information:
Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
General Manager: Jochen Krause
Registered Office: Commercial Register Mannheim HRB 107883
============================================================================

Re: Create Content-MD5 hash

Posted by Robert Newson <rn...@apache.org>.
I'm pretty sure MD5 verification is only available for standalone
attachments right now.

B.

On 27 September 2011 18:32, Moritz Post <mp...@eclipsesource.com> wrote:
> Hi Robert
>
> No problem. The issue has been solved. So how about validating newly created
> documents?
>
> Greets
> Moritz
>
> On Tue, Sep 27, 2011 at 5:52 PM, Robert Newson <rn...@apache.org> wrote:
>
>> Heh, I totally missed that you hadn't converted to hex in the middle,
>> sorry.
>>
>> On 27 September 2011 16:18, Moritz Post <mp...@eclipsesource.com> wrote:
>> > Hi Keith
>> >
>> > Thanks for the hint. I have actually applied it onto a java
>> implementation
>> > of the hash generation and it produced a correct hash value. Here is my
>> > implementation:
>> >
>> > MessageDigest md5 = MessageDigest.getInstance("MD5");
>> > byte[] digest = md5.digest("{ \"valid\": \"json\" }".getBytes());
>> > byte[] hash = Base64.encodeBase64(digest);
>> > System.out.println(new String(hash));
>> >
>> > Output: S/OqwXHe0WedNQHMvT4NhQ==
>> >
>> > It uses Base64 from the apache commons project. I have used that has
>> value
>> >
>> > Now onto my final question: can i also validated the content of a couchdb
>> > document i create by uploading a json document?
>> >
>> > Regards
>> > Moritz Post
>> >
>> > On Tue, Sep 27, 2011 at 4:57 PM, Keith Gable <ziggy@ignition-project.com
>> >wrote:
>> >
>> >> According to RFC2616 (
>> >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html),
>> >> section 14.15, you need the Base64 encoding of the actual MD5 bits, not
>> the
>> >> base64 encoding of the hex encoding of MD5 bits.
>> >>
>> >> In Ruby, after you require the base64 and digest/md5 libraries, you can
>> >> generate a Base64 of the raw bits by doing this:
>> >>
>> >> Base64.encode64(Digest::MD5.digest(your_file_iostream))
>> >>
>> >>
>> >> Hope that helps.
>> >>
>> >> ---
>> >> Keith Gable
>> >> A+ Certified Professional
>> >> Network+ Certified Professional
>> >> Web Developer
>> >>
>> >>
>> >>
>> >> On Tue, Sep 27, 2011 at 9:47 AM, Moritz Post <mpost@eclipsesource.com
>> >> >wrote:
>> >>
>> >> > Hi Robert
>> >> >
>> >> > Thanks for the reply. Using -n does produce a different echo output
>> but
>> >> it
>> >> > does not produce a hash consumable by the couchdb:
>> >> >
>> >> > $ echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>> >> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODU=
>> >> >
>> >> > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>> >> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>> >> >
>> >> > Using the hash with the = at the end i still get the response:
>> >> > {"error":"content_md5_mismatch","reason":"Possible message
>> corruption."}
>> >> >
>> >> > Greets
>> >> > Moritz
>> >> >
>> >> > On Tue, Sep 27, 2011 at 4:19 PM, Robert Newson <rn...@apache.org>
>> >> wrote:
>> >> >
>> >> > > try
>> >> > >
>> >> > > echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>> >> > >
>> >> > > as echo includes a new line unless you use -n.
>> >> > >
>> >> > > B.
>> >> > >
>> >> > > On 27 September 2011 14:29, Moritz Post <mp...@eclipsesource.com>
>> >> wrote:
>> >> > > > Hallo CouchDB
>> >> > > >
>> >> > > > I am trying to validate the integrity of data i upload to the
>> >> couchdb.
>> >> > > > Therefore i provide a valid MD5 hash alongside my PUT request.
>> From
>> >> > what
>> >> > > i
>> >> > > > have gathered this md5 has to be base64 encoded. My problem is
>> that i
>> >> > am
>> >> > > not
>> >> > > > able to create a valid hash. All i get is:
>> >> > > >
>> >> > > > {"error":"content_md5_mismatch","reason":"Possible message
>> >> > corruption."}
>> >> > > >
>> >> > > > I am currently experimenting with a CURL based approach but will
>> need
>> >> > > > to incorporate the hash creation into a java program later. Here
>> is
>> >> > what
>> >> > > is
>> >> > > > did do create the md5 hash:
>> >> > > >
>> >> > > > $ md5sum test.json
>> >> > > > 4bf3aac171ded1679d3501ccbd3e0d85  test.json
>> >> > > > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>> >> > > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>> >> > > >
>> >> > > > So i have a hash value and now use it in my PUT request (verbose
>> >> > output):
>> >> > > >
>> >> > > > $ curl -X PUT -H "Content-MD5:
>> >> > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
>> >> > > > -H "Content-Type: application/json" -v -d @test.json
>> >> > > >
>> >> > >
>> >> >
>> >>
>> http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
>> >> > > > * About to connect() to 192.168.6.168 port 5984 (#0)
>> >> > > > *   Trying 192.168.6.168... connected
>> >> > > > * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
>> >> > > > * Server auth using Basic with user 'admin'
>> >> > > >> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
>> >> > HTTP/1.1
>> >> > > >> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3
>> >> > > OpenSSL/0.9.8o
>> >> > > > zlib/1.2.3.4 libidn/1.18
>> >> > > >> Host: 192.168.6.168:5984
>> >> > > >> Accept: */*
>> >> > > >> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>> >> > > >> Content-Type: application/json
>> >> > > >> Content-Length: 19
>> >> > > >>
>> >> > > > < HTTP/1.1 400 Bad Request
>> >> > > > < Server: CouchDB/1.0.2 (Erlang OTP/R14B)
>> >> > > > < Date: Tue, 27 Sep 2011 13:23:38 GMT
>> >> > > > < Content-Type: text/plain;charset=utf-8
>> >> > > > < Content-Length: 73
>> >> > > > < Cache-Control: must-revalidate
>> >> > > > <
>> >> > > > {"error":"content_md5_mismatch","reason":"Possible message
>> >> > corruption."}
>> >> > > > * Connection #0 to host 192.168.6.168 left intact
>> >> > > > * Closing connection #0
>> >> > > >
>> >> > > > I am running a couchdb 1.0.3.
>> >> > > >
>> >> > > > The question is: how to properly create a md5 hash that validates
>> the
>> >> > > > upload.
>> >> > > >
>> >> > > > Additionally i would like to know if it is only possible to
>> validated
>> >> > > > attachment uploads or is it also possible to validated the
>> uploaded
>> >> > json
>> >> > > > documents one creates in the couchdb?
>> >> > > >
>> >> > > > Thank you
>> >> > > > Moritz Post
>> >> > > >
>> >> > > > --
>> >> > > > -----------------------------------
>> >> > > > Moritz Post
>> >> > > > EclipseSource
>> >> > > > Email: mpost@eclipsesource.com
>> >> > > > Tel: +49-721-66-47-33-33
>> >> > > > Fax: +49-721-66-47-33-29
>> >> > > > http://www.eclipsesource.com/
>> >> > > > ========================= Legal Disclaimer
>> >> > > =================================
>> >> > > > According to Section 80 of the German Corporation Act
>> >> > > > Innoopract Informationssysteme GmbH must indicate the following
>> >> > > information:
>> >> > > > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
>> >> > > > General Manager: Jochen Krause
>> >> > > > Registered Office: Commercial Register Mannheim HRB 107883
>> >> > > >
>> >> > >
>> >> >
>> >>
>> ============================================================================
>> >> > > >
>> >> > >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > -----------------------------------
>> >> > Moritz Post
>> >> > EclipseSource
>> >> > Email: mpost@eclipsesource.com
>> >> > Tel: +49-721-66-47-33-33
>> >> > Fax: +49-721-66-47-33-29
>> >> > http://www.eclipsesource.com/
>> >> > ========================= Legal Disclaimer
>> >> > =================================
>> >> > According to Section 80 of the German Corporation Act
>> >> > Innoopract Informationssysteme GmbH must indicate the following
>> >> > information:
>> >> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
>> >> > General Manager: Jochen Krause
>> >> > Registered Office: Commercial Register Mannheim HRB 107883
>> >> >
>> >> >
>> >>
>> ============================================================================
>> >> >
>> >>
>> >
>> >
>> >
>> > --
>> > -----------------------------------
>> > Moritz Post
>> > EclipseSource
>> > Email: mpost@eclipsesource.com
>> > Tel: +49-721-66-47-33-33
>> > Fax: +49-721-66-47-33-29
>> > http://www.eclipsesource.com/
>> > ========================= Legal Disclaimer
>> =================================
>> > According to Section 80 of the German Corporation Act
>> > Innoopract Informationssysteme GmbH must indicate the following
>> information:
>> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
>> > General Manager: Jochen Krause
>> > Registered Office: Commercial Register Mannheim HRB 107883
>> >
>> ============================================================================
>> >
>>
>
>
>
> --
> -----------------------------------
> Moritz Post
> EclipseSource
> Email: mpost@eclipsesource.com
> Tel: +49-721-66-47-33-33
> Fax: +49-721-66-47-33-29
> http://www.eclipsesource.com/
> ========================= Legal Disclaimer =================================
> According to Section 80 of the German Corporation Act
> Innoopract Informationssysteme GmbH must indicate the following information:
> Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> General Manager: Jochen Krause
> Registered Office: Commercial Register Mannheim HRB 107883
> ============================================================================
>

Re: Create Content-MD5 hash

Posted by Moritz Post <mp...@eclipsesource.com>.
Hi Robert

No problem. The issue has been solved. So how about validating newly created
documents?

Greets
Moritz

On Tue, Sep 27, 2011 at 5:52 PM, Robert Newson <rn...@apache.org> wrote:

> Heh, I totally missed that you hadn't converted to hex in the middle,
> sorry.
>
> On 27 September 2011 16:18, Moritz Post <mp...@eclipsesource.com> wrote:
> > Hi Keith
> >
> > Thanks for the hint. I have actually applied it onto a java
> implementation
> > of the hash generation and it produced a correct hash value. Here is my
> > implementation:
> >
> > MessageDigest md5 = MessageDigest.getInstance("MD5");
> > byte[] digest = md5.digest("{ \"valid\": \"json\" }".getBytes());
> > byte[] hash = Base64.encodeBase64(digest);
> > System.out.println(new String(hash));
> >
> > Output: S/OqwXHe0WedNQHMvT4NhQ==
> >
> > It uses Base64 from the apache commons project. I have used that has
> value
> >
> > Now onto my final question: can i also validated the content of a couchdb
> > document i create by uploading a json document?
> >
> > Regards
> > Moritz Post
> >
> > On Tue, Sep 27, 2011 at 4:57 PM, Keith Gable <ziggy@ignition-project.com
> >wrote:
> >
> >> According to RFC2616 (
> >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html),
> >> section 14.15, you need the Base64 encoding of the actual MD5 bits, not
> the
> >> base64 encoding of the hex encoding of MD5 bits.
> >>
> >> In Ruby, after you require the base64 and digest/md5 libraries, you can
> >> generate a Base64 of the raw bits by doing this:
> >>
> >> Base64.encode64(Digest::MD5.digest(your_file_iostream))
> >>
> >>
> >> Hope that helps.
> >>
> >> ---
> >> Keith Gable
> >> A+ Certified Professional
> >> Network+ Certified Professional
> >> Web Developer
> >>
> >>
> >>
> >> On Tue, Sep 27, 2011 at 9:47 AM, Moritz Post <mpost@eclipsesource.com
> >> >wrote:
> >>
> >> > Hi Robert
> >> >
> >> > Thanks for the reply. Using -n does produce a different echo output
> but
> >> it
> >> > does not produce a hash consumable by the couchdb:
> >> >
> >> > $ echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODU=
> >> >
> >> > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >> >
> >> > Using the hash with the = at the end i still get the response:
> >> > {"error":"content_md5_mismatch","reason":"Possible message
> corruption."}
> >> >
> >> > Greets
> >> > Moritz
> >> >
> >> > On Tue, Sep 27, 2011 at 4:19 PM, Robert Newson <rn...@apache.org>
> >> wrote:
> >> >
> >> > > try
> >> > >
> >> > > echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >> > >
> >> > > as echo includes a new line unless you use -n.
> >> > >
> >> > > B.
> >> > >
> >> > > On 27 September 2011 14:29, Moritz Post <mp...@eclipsesource.com>
> >> wrote:
> >> > > > Hallo CouchDB
> >> > > >
> >> > > > I am trying to validate the integrity of data i upload to the
> >> couchdb.
> >> > > > Therefore i provide a valid MD5 hash alongside my PUT request.
> From
> >> > what
> >> > > i
> >> > > > have gathered this md5 has to be base64 encoded. My problem is
> that i
> >> > am
> >> > > not
> >> > > > able to create a valid hash. All i get is:
> >> > > >
> >> > > > {"error":"content_md5_mismatch","reason":"Possible message
> >> > corruption."}
> >> > > >
> >> > > > I am currently experimenting with a CURL based approach but will
> need
> >> > > > to incorporate the hash creation into a java program later. Here
> is
> >> > what
> >> > > is
> >> > > > did do create the md5 hash:
> >> > > >
> >> > > > $ md5sum test.json
> >> > > > 4bf3aac171ded1679d3501ccbd3e0d85  test.json
> >> > > > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >> > > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >> > > >
> >> > > > So i have a hash value and now use it in my PUT request (verbose
> >> > output):
> >> > > >
> >> > > > $ curl -X PUT -H "Content-MD5:
> >> > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
> >> > > > -H "Content-Type: application/json" -v -d @test.json
> >> > > >
> >> > >
> >> >
> >>
> http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> >> > > > * About to connect() to 192.168.6.168 port 5984 (#0)
> >> > > > *   Trying 192.168.6.168... connected
> >> > > > * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
> >> > > > * Server auth using Basic with user 'admin'
> >> > > >> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> >> > HTTP/1.1
> >> > > >> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3
> >> > > OpenSSL/0.9.8o
> >> > > > zlib/1.2.3.4 libidn/1.18
> >> > > >> Host: 192.168.6.168:5984
> >> > > >> Accept: */*
> >> > > >> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >> > > >> Content-Type: application/json
> >> > > >> Content-Length: 19
> >> > > >>
> >> > > > < HTTP/1.1 400 Bad Request
> >> > > > < Server: CouchDB/1.0.2 (Erlang OTP/R14B)
> >> > > > < Date: Tue, 27 Sep 2011 13:23:38 GMT
> >> > > > < Content-Type: text/plain;charset=utf-8
> >> > > > < Content-Length: 73
> >> > > > < Cache-Control: must-revalidate
> >> > > > <
> >> > > > {"error":"content_md5_mismatch","reason":"Possible message
> >> > corruption."}
> >> > > > * Connection #0 to host 192.168.6.168 left intact
> >> > > > * Closing connection #0
> >> > > >
> >> > > > I am running a couchdb 1.0.3.
> >> > > >
> >> > > > The question is: how to properly create a md5 hash that validates
> the
> >> > > > upload.
> >> > > >
> >> > > > Additionally i would like to know if it is only possible to
> validated
> >> > > > attachment uploads or is it also possible to validated the
> uploaded
> >> > json
> >> > > > documents one creates in the couchdb?
> >> > > >
> >> > > > Thank you
> >> > > > Moritz Post
> >> > > >
> >> > > > --
> >> > > > -----------------------------------
> >> > > > Moritz Post
> >> > > > EclipseSource
> >> > > > Email: mpost@eclipsesource.com
> >> > > > Tel: +49-721-66-47-33-33
> >> > > > Fax: +49-721-66-47-33-29
> >> > > > http://www.eclipsesource.com/
> >> > > > ========================= Legal Disclaimer
> >> > > =================================
> >> > > > According to Section 80 of the German Corporation Act
> >> > > > Innoopract Informationssysteme GmbH must indicate the following
> >> > > information:
> >> > > > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> >> > > > General Manager: Jochen Krause
> >> > > > Registered Office: Commercial Register Mannheim HRB 107883
> >> > > >
> >> > >
> >> >
> >>
> ============================================================================
> >> > > >
> >> > >
> >> >
> >> >
> >> >
> >> > --
> >> > -----------------------------------
> >> > Moritz Post
> >> > EclipseSource
> >> > Email: mpost@eclipsesource.com
> >> > Tel: +49-721-66-47-33-33
> >> > Fax: +49-721-66-47-33-29
> >> > http://www.eclipsesource.com/
> >> > ========================= Legal Disclaimer
> >> > =================================
> >> > According to Section 80 of the German Corporation Act
> >> > Innoopract Informationssysteme GmbH must indicate the following
> >> > information:
> >> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> >> > General Manager: Jochen Krause
> >> > Registered Office: Commercial Register Mannheim HRB 107883
> >> >
> >> >
> >>
> ============================================================================
> >> >
> >>
> >
> >
> >
> > --
> > -----------------------------------
> > Moritz Post
> > EclipseSource
> > Email: mpost@eclipsesource.com
> > Tel: +49-721-66-47-33-33
> > Fax: +49-721-66-47-33-29
> > http://www.eclipsesource.com/
> > ========================= Legal Disclaimer
> =================================
> > According to Section 80 of the German Corporation Act
> > Innoopract Informationssysteme GmbH must indicate the following
> information:
> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> > General Manager: Jochen Krause
> > Registered Office: Commercial Register Mannheim HRB 107883
> >
> ============================================================================
> >
>



-- 
-----------------------------------
Moritz Post
EclipseSource
Email: mpost@eclipsesource.com
Tel: +49-721-66-47-33-33
Fax: +49-721-66-47-33-29
http://www.eclipsesource.com/
========================= Legal Disclaimer =================================
According to Section 80 of the German Corporation Act
Innoopract Informationssysteme GmbH must indicate the following information:
Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
General Manager: Jochen Krause
Registered Office: Commercial Register Mannheim HRB 107883
============================================================================

Re: Create Content-MD5 hash

Posted by Robert Newson <rn...@apache.org>.
Heh, I totally missed that you hadn't converted to hex in the middle, sorry.

On 27 September 2011 16:18, Moritz Post <mp...@eclipsesource.com> wrote:
> Hi Keith
>
> Thanks for the hint. I have actually applied it onto a java implementation
> of the hash generation and it produced a correct hash value. Here is my
> implementation:
>
> MessageDigest md5 = MessageDigest.getInstance("MD5");
> byte[] digest = md5.digest("{ \"valid\": \"json\" }".getBytes());
> byte[] hash = Base64.encodeBase64(digest);
> System.out.println(new String(hash));
>
> Output: S/OqwXHe0WedNQHMvT4NhQ==
>
> It uses Base64 from the apache commons project. I have used that has value
>
> Now onto my final question: can i also validated the content of a couchdb
> document i create by uploading a json document?
>
> Regards
> Moritz Post
>
> On Tue, Sep 27, 2011 at 4:57 PM, Keith Gable <zi...@ignition-project.com>wrote:
>
>> According to RFC2616 (
>> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html),
>> section 14.15, you need the Base64 encoding of the actual MD5 bits, not the
>> base64 encoding of the hex encoding of MD5 bits.
>>
>> In Ruby, after you require the base64 and digest/md5 libraries, you can
>> generate a Base64 of the raw bits by doing this:
>>
>> Base64.encode64(Digest::MD5.digest(your_file_iostream))
>>
>>
>> Hope that helps.
>>
>> ---
>> Keith Gable
>> A+ Certified Professional
>> Network+ Certified Professional
>> Web Developer
>>
>>
>>
>> On Tue, Sep 27, 2011 at 9:47 AM, Moritz Post <mpost@eclipsesource.com
>> >wrote:
>>
>> > Hi Robert
>> >
>> > Thanks for the reply. Using -n does produce a different echo output but
>> it
>> > does not produce a hash consumable by the couchdb:
>> >
>> > $ echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODU=
>> >
>> > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>> >
>> > Using the hash with the = at the end i still get the response:
>> > {"error":"content_md5_mismatch","reason":"Possible message corruption."}
>> >
>> > Greets
>> > Moritz
>> >
>> > On Tue, Sep 27, 2011 at 4:19 PM, Robert Newson <rn...@apache.org>
>> wrote:
>> >
>> > > try
>> > >
>> > > echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>> > >
>> > > as echo includes a new line unless you use -n.
>> > >
>> > > B.
>> > >
>> > > On 27 September 2011 14:29, Moritz Post <mp...@eclipsesource.com>
>> wrote:
>> > > > Hallo CouchDB
>> > > >
>> > > > I am trying to validate the integrity of data i upload to the
>> couchdb.
>> > > > Therefore i provide a valid MD5 hash alongside my PUT request. From
>> > what
>> > > i
>> > > > have gathered this md5 has to be base64 encoded. My problem is that i
>> > am
>> > > not
>> > > > able to create a valid hash. All i get is:
>> > > >
>> > > > {"error":"content_md5_mismatch","reason":"Possible message
>> > corruption."}
>> > > >
>> > > > I am currently experimenting with a CURL based approach but will need
>> > > > to incorporate the hash creation into a java program later. Here is
>> > what
>> > > is
>> > > > did do create the md5 hash:
>> > > >
>> > > > $ md5sum test.json
>> > > > 4bf3aac171ded1679d3501ccbd3e0d85  test.json
>> > > > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>> > > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>> > > >
>> > > > So i have a hash value and now use it in my PUT request (verbose
>> > output):
>> > > >
>> > > > $ curl -X PUT -H "Content-MD5:
>> > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
>> > > > -H "Content-Type: application/json" -v -d @test.json
>> > > >
>> > >
>> >
>> http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
>> > > > * About to connect() to 192.168.6.168 port 5984 (#0)
>> > > > *   Trying 192.168.6.168... connected
>> > > > * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
>> > > > * Server auth using Basic with user 'admin'
>> > > >> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
>> > HTTP/1.1
>> > > >> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3
>> > > OpenSSL/0.9.8o
>> > > > zlib/1.2.3.4 libidn/1.18
>> > > >> Host: 192.168.6.168:5984
>> > > >> Accept: */*
>> > > >> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>> > > >> Content-Type: application/json
>> > > >> Content-Length: 19
>> > > >>
>> > > > < HTTP/1.1 400 Bad Request
>> > > > < Server: CouchDB/1.0.2 (Erlang OTP/R14B)
>> > > > < Date: Tue, 27 Sep 2011 13:23:38 GMT
>> > > > < Content-Type: text/plain;charset=utf-8
>> > > > < Content-Length: 73
>> > > > < Cache-Control: must-revalidate
>> > > > <
>> > > > {"error":"content_md5_mismatch","reason":"Possible message
>> > corruption."}
>> > > > * Connection #0 to host 192.168.6.168 left intact
>> > > > * Closing connection #0
>> > > >
>> > > > I am running a couchdb 1.0.3.
>> > > >
>> > > > The question is: how to properly create a md5 hash that validates the
>> > > > upload.
>> > > >
>> > > > Additionally i would like to know if it is only possible to validated
>> > > > attachment uploads or is it also possible to validated the uploaded
>> > json
>> > > > documents one creates in the couchdb?
>> > > >
>> > > > Thank you
>> > > > Moritz Post
>> > > >
>> > > > --
>> > > > -----------------------------------
>> > > > Moritz Post
>> > > > EclipseSource
>> > > > Email: mpost@eclipsesource.com
>> > > > Tel: +49-721-66-47-33-33
>> > > > Fax: +49-721-66-47-33-29
>> > > > http://www.eclipsesource.com/
>> > > > ========================= Legal Disclaimer
>> > > =================================
>> > > > According to Section 80 of the German Corporation Act
>> > > > Innoopract Informationssysteme GmbH must indicate the following
>> > > information:
>> > > > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
>> > > > General Manager: Jochen Krause
>> > > > Registered Office: Commercial Register Mannheim HRB 107883
>> > > >
>> > >
>> >
>> ============================================================================
>> > > >
>> > >
>> >
>> >
>> >
>> > --
>> > -----------------------------------
>> > Moritz Post
>> > EclipseSource
>> > Email: mpost@eclipsesource.com
>> > Tel: +49-721-66-47-33-33
>> > Fax: +49-721-66-47-33-29
>> > http://www.eclipsesource.com/
>> > ========================= Legal Disclaimer
>> > =================================
>> > According to Section 80 of the German Corporation Act
>> > Innoopract Informationssysteme GmbH must indicate the following
>> > information:
>> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
>> > General Manager: Jochen Krause
>> > Registered Office: Commercial Register Mannheim HRB 107883
>> >
>> >
>> ============================================================================
>> >
>>
>
>
>
> --
> -----------------------------------
> Moritz Post
> EclipseSource
> Email: mpost@eclipsesource.com
> Tel: +49-721-66-47-33-33
> Fax: +49-721-66-47-33-29
> http://www.eclipsesource.com/
> ========================= Legal Disclaimer =================================
> According to Section 80 of the German Corporation Act
> Innoopract Informationssysteme GmbH must indicate the following information:
> Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> General Manager: Jochen Krause
> Registered Office: Commercial Register Mannheim HRB 107883
> ============================================================================
>

Re: Create Content-MD5 hash

Posted by Moritz Post <mp...@eclipsesource.com>.
Hi Keith

Thanks for the hint. I have actually applied it onto a java implementation
of the hash generation and it produced a correct hash value. Here is my
implementation:

MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] digest = md5.digest("{ \"valid\": \"json\" }".getBytes());
byte[] hash = Base64.encodeBase64(digest);
System.out.println(new String(hash));

Output: S/OqwXHe0WedNQHMvT4NhQ==

It uses Base64 from the apache commons project. I have used that has value

Now onto my final question: can i also validated the content of a couchdb
document i create by uploading a json document?

Regards
Moritz Post

On Tue, Sep 27, 2011 at 4:57 PM, Keith Gable <zi...@ignition-project.com>wrote:

> According to RFC2616 (
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html),
> section 14.15, you need the Base64 encoding of the actual MD5 bits, not the
> base64 encoding of the hex encoding of MD5 bits.
>
> In Ruby, after you require the base64 and digest/md5 libraries, you can
> generate a Base64 of the raw bits by doing this:
>
> Base64.encode64(Digest::MD5.digest(your_file_iostream))
>
>
> Hope that helps.
>
> ---
> Keith Gable
> A+ Certified Professional
> Network+ Certified Professional
> Web Developer
>
>
>
> On Tue, Sep 27, 2011 at 9:47 AM, Moritz Post <mpost@eclipsesource.com
> >wrote:
>
> > Hi Robert
> >
> > Thanks for the reply. Using -n does produce a different echo output but
> it
> > does not produce a hash consumable by the couchdb:
> >
> > $ echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODU=
> >
> > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >
> > Using the hash with the = at the end i still get the response:
> > {"error":"content_md5_mismatch","reason":"Possible message corruption."}
> >
> > Greets
> > Moritz
> >
> > On Tue, Sep 27, 2011 at 4:19 PM, Robert Newson <rn...@apache.org>
> wrote:
> >
> > > try
> > >
> > > echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> > >
> > > as echo includes a new line unless you use -n.
> > >
> > > B.
> > >
> > > On 27 September 2011 14:29, Moritz Post <mp...@eclipsesource.com>
> wrote:
> > > > Hallo CouchDB
> > > >
> > > > I am trying to validate the integrity of data i upload to the
> couchdb.
> > > > Therefore i provide a valid MD5 hash alongside my PUT request. From
> > what
> > > i
> > > > have gathered this md5 has to be base64 encoded. My problem is that i
> > am
> > > not
> > > > able to create a valid hash. All i get is:
> > > >
> > > > {"error":"content_md5_mismatch","reason":"Possible message
> > corruption."}
> > > >
> > > > I am currently experimenting with a CURL based approach but will need
> > > > to incorporate the hash creation into a java program later. Here is
> > what
> > > is
> > > > did do create the md5 hash:
> > > >
> > > > $ md5sum test.json
> > > > 4bf3aac171ded1679d3501ccbd3e0d85  test.json
> > > > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> > > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> > > >
> > > > So i have a hash value and now use it in my PUT request (verbose
> > output):
> > > >
> > > > $ curl -X PUT -H "Content-MD5:
> > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
> > > > -H "Content-Type: application/json" -v -d @test.json
> > > >
> > >
> >
> http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> > > > * About to connect() to 192.168.6.168 port 5984 (#0)
> > > > *   Trying 192.168.6.168... connected
> > > > * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
> > > > * Server auth using Basic with user 'admin'
> > > >> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> > HTTP/1.1
> > > >> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3
> > > OpenSSL/0.9.8o
> > > > zlib/1.2.3.4 libidn/1.18
> > > >> Host: 192.168.6.168:5984
> > > >> Accept: */*
> > > >> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> > > >> Content-Type: application/json
> > > >> Content-Length: 19
> > > >>
> > > > < HTTP/1.1 400 Bad Request
> > > > < Server: CouchDB/1.0.2 (Erlang OTP/R14B)
> > > > < Date: Tue, 27 Sep 2011 13:23:38 GMT
> > > > < Content-Type: text/plain;charset=utf-8
> > > > < Content-Length: 73
> > > > < Cache-Control: must-revalidate
> > > > <
> > > > {"error":"content_md5_mismatch","reason":"Possible message
> > corruption."}
> > > > * Connection #0 to host 192.168.6.168 left intact
> > > > * Closing connection #0
> > > >
> > > > I am running a couchdb 1.0.3.
> > > >
> > > > The question is: how to properly create a md5 hash that validates the
> > > > upload.
> > > >
> > > > Additionally i would like to know if it is only possible to validated
> > > > attachment uploads or is it also possible to validated the uploaded
> > json
> > > > documents one creates in the couchdb?
> > > >
> > > > Thank you
> > > > Moritz Post
> > > >
> > > > --
> > > > -----------------------------------
> > > > Moritz Post
> > > > EclipseSource
> > > > Email: mpost@eclipsesource.com
> > > > Tel: +49-721-66-47-33-33
> > > > Fax: +49-721-66-47-33-29
> > > > http://www.eclipsesource.com/
> > > > ========================= Legal Disclaimer
> > > =================================
> > > > According to Section 80 of the German Corporation Act
> > > > Innoopract Informationssysteme GmbH must indicate the following
> > > information:
> > > > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> > > > General Manager: Jochen Krause
> > > > Registered Office: Commercial Register Mannheim HRB 107883
> > > >
> > >
> >
> ============================================================================
> > > >
> > >
> >
> >
> >
> > --
> > -----------------------------------
> > Moritz Post
> > EclipseSource
> > Email: mpost@eclipsesource.com
> > Tel: +49-721-66-47-33-33
> > Fax: +49-721-66-47-33-29
> > http://www.eclipsesource.com/
> > ========================= Legal Disclaimer
> > =================================
> > According to Section 80 of the German Corporation Act
> > Innoopract Informationssysteme GmbH must indicate the following
> > information:
> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> > General Manager: Jochen Krause
> > Registered Office: Commercial Register Mannheim HRB 107883
> >
> >
> ============================================================================
> >
>



-- 
-----------------------------------
Moritz Post
EclipseSource
Email: mpost@eclipsesource.com
Tel: +49-721-66-47-33-33
Fax: +49-721-66-47-33-29
http://www.eclipsesource.com/
========================= Legal Disclaimer =================================
According to Section 80 of the German Corporation Act
Innoopract Informationssysteme GmbH must indicate the following information:
Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
General Manager: Jochen Krause
Registered Office: Commercial Register Mannheim HRB 107883
============================================================================

Re: Create Content-MD5 hash

Posted by Keith Gable <zi...@ignition-project.com>.
According to RFC2616 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html),
section 14.15, you need the Base64 encoding of the actual MD5 bits, not the
base64 encoding of the hex encoding of MD5 bits.

In Ruby, after you require the base64 and digest/md5 libraries, you can
generate a Base64 of the raw bits by doing this:

Base64.encode64(Digest::MD5.digest(your_file_iostream))


Hope that helps.

---
Keith Gable
A+ Certified Professional
Network+ Certified Professional
Web Developer



On Tue, Sep 27, 2011 at 9:47 AM, Moritz Post <mp...@eclipsesource.com>wrote:

> Hi Robert
>
> Thanks for the reply. Using -n does produce a different echo output but it
> does not produce a hash consumable by the couchdb:
>
> $ echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODU=
>
> $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>
> Using the hash with the = at the end i still get the response:
> {"error":"content_md5_mismatch","reason":"Possible message corruption."}
>
> Greets
> Moritz
>
> On Tue, Sep 27, 2011 at 4:19 PM, Robert Newson <rn...@apache.org> wrote:
>
> > try
> >
> > echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> >
> > as echo includes a new line unless you use -n.
> >
> > B.
> >
> > On 27 September 2011 14:29, Moritz Post <mp...@eclipsesource.com> wrote:
> > > Hallo CouchDB
> > >
> > > I am trying to validate the integrity of data i upload to the couchdb.
> > > Therefore i provide a valid MD5 hash alongside my PUT request. From
> what
> > i
> > > have gathered this md5 has to be base64 encoded. My problem is that i
> am
> > not
> > > able to create a valid hash. All i get is:
> > >
> > > {"error":"content_md5_mismatch","reason":"Possible message
> corruption."}
> > >
> > > I am currently experimenting with a CURL based approach but will need
> > > to incorporate the hash creation into a java program later. Here is
> what
> > is
> > > did do create the md5 hash:
> > >
> > > $ md5sum test.json
> > > 4bf3aac171ded1679d3501ccbd3e0d85  test.json
> > > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> > >
> > > So i have a hash value and now use it in my PUT request (verbose
> output):
> > >
> > > $ curl -X PUT -H "Content-MD5:
> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
> > > -H "Content-Type: application/json" -v -d @test.json
> > >
> >
> http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> > > * About to connect() to 192.168.6.168 port 5984 (#0)
> > > *   Trying 192.168.6.168... connected
> > > * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
> > > * Server auth using Basic with user 'admin'
> > >> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> HTTP/1.1
> > >> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3
> > OpenSSL/0.9.8o
> > > zlib/1.2.3.4 libidn/1.18
> > >> Host: 192.168.6.168:5984
> > >> Accept: */*
> > >> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> > >> Content-Type: application/json
> > >> Content-Length: 19
> > >>
> > > < HTTP/1.1 400 Bad Request
> > > < Server: CouchDB/1.0.2 (Erlang OTP/R14B)
> > > < Date: Tue, 27 Sep 2011 13:23:38 GMT
> > > < Content-Type: text/plain;charset=utf-8
> > > < Content-Length: 73
> > > < Cache-Control: must-revalidate
> > > <
> > > {"error":"content_md5_mismatch","reason":"Possible message
> corruption."}
> > > * Connection #0 to host 192.168.6.168 left intact
> > > * Closing connection #0
> > >
> > > I am running a couchdb 1.0.3.
> > >
> > > The question is: how to properly create a md5 hash that validates the
> > > upload.
> > >
> > > Additionally i would like to know if it is only possible to validated
> > > attachment uploads or is it also possible to validated the uploaded
> json
> > > documents one creates in the couchdb?
> > >
> > > Thank you
> > > Moritz Post
> > >
> > > --
> > > -----------------------------------
> > > Moritz Post
> > > EclipseSource
> > > Email: mpost@eclipsesource.com
> > > Tel: +49-721-66-47-33-33
> > > Fax: +49-721-66-47-33-29
> > > http://www.eclipsesource.com/
> > > ========================= Legal Disclaimer
> > =================================
> > > According to Section 80 of the German Corporation Act
> > > Innoopract Informationssysteme GmbH must indicate the following
> > information:
> > > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> > > General Manager: Jochen Krause
> > > Registered Office: Commercial Register Mannheim HRB 107883
> > >
> >
> ============================================================================
> > >
> >
>
>
>
> --
> -----------------------------------
> Moritz Post
> EclipseSource
> Email: mpost@eclipsesource.com
> Tel: +49-721-66-47-33-33
> Fax: +49-721-66-47-33-29
> http://www.eclipsesource.com/
> ========================= Legal Disclaimer
> =================================
> According to Section 80 of the German Corporation Act
> Innoopract Informationssysteme GmbH must indicate the following
> information:
> Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> General Manager: Jochen Krause
> Registered Office: Commercial Register Mannheim HRB 107883
>
> ============================================================================
>

Re: Create Content-MD5 hash

Posted by Moritz Post <mp...@eclipsesource.com>.
Hi Robert

Thanks for the reply. Using -n does produce a different echo output but it
does not produce a hash consumable by the couchdb:

$ echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODU=

$ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK

Using the hash with the = at the end i still get the response:
{"error":"content_md5_mismatch","reason":"Possible message corruption."}

Greets
Moritz

On Tue, Sep 27, 2011 at 4:19 PM, Robert Newson <rn...@apache.org> wrote:

> try
>
> echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64
>
> as echo includes a new line unless you use -n.
>
> B.
>
> On 27 September 2011 14:29, Moritz Post <mp...@eclipsesource.com> wrote:
> > Hallo CouchDB
> >
> > I am trying to validate the integrity of data i upload to the couchdb.
> > Therefore i provide a valid MD5 hash alongside my PUT request. From what
> i
> > have gathered this md5 has to be base64 encoded. My problem is that i am
> not
> > able to create a valid hash. All i get is:
> >
> > {"error":"content_md5_mismatch","reason":"Possible message corruption."}
> >
> > I am currently experimenting with a CURL based approach but will need
> > to incorporate the hash creation into a java program later. Here is what
> is
> > did do create the md5 hash:
> >
> > $ md5sum test.json
> > 4bf3aac171ded1679d3501ccbd3e0d85  test.json
> > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >
> > So i have a hash value and now use it in my PUT request (verbose output):
> >
> > $ curl -X PUT -H "Content-MD5:
> NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
> > -H "Content-Type: application/json" -v -d @test.json
> >
> http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> > * About to connect() to 192.168.6.168 port 5984 (#0)
> > *   Trying 192.168.6.168... connected
> > * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
> > * Server auth using Basic with user 'admin'
> >> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb HTTP/1.1
> >> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3
> OpenSSL/0.9.8o
> > zlib/1.2.3.4 libidn/1.18
> >> Host: 192.168.6.168:5984
> >> Accept: */*
> >> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
> >> Content-Type: application/json
> >> Content-Length: 19
> >>
> > < HTTP/1.1 400 Bad Request
> > < Server: CouchDB/1.0.2 (Erlang OTP/R14B)
> > < Date: Tue, 27 Sep 2011 13:23:38 GMT
> > < Content-Type: text/plain;charset=utf-8
> > < Content-Length: 73
> > < Cache-Control: must-revalidate
> > <
> > {"error":"content_md5_mismatch","reason":"Possible message corruption."}
> > * Connection #0 to host 192.168.6.168 left intact
> > * Closing connection #0
> >
> > I am running a couchdb 1.0.3.
> >
> > The question is: how to properly create a md5 hash that validates the
> > upload.
> >
> > Additionally i would like to know if it is only possible to validated
> > attachment uploads or is it also possible to validated the uploaded json
> > documents one creates in the couchdb?
> >
> > Thank you
> > Moritz Post
> >
> > --
> > -----------------------------------
> > Moritz Post
> > EclipseSource
> > Email: mpost@eclipsesource.com
> > Tel: +49-721-66-47-33-33
> > Fax: +49-721-66-47-33-29
> > http://www.eclipsesource.com/
> > ========================= Legal Disclaimer
> =================================
> > According to Section 80 of the German Corporation Act
> > Innoopract Informationssysteme GmbH must indicate the following
> information:
> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> > General Manager: Jochen Krause
> > Registered Office: Commercial Register Mannheim HRB 107883
> >
> ============================================================================
> >
>



-- 
-----------------------------------
Moritz Post
EclipseSource
Email: mpost@eclipsesource.com
Tel: +49-721-66-47-33-33
Fax: +49-721-66-47-33-29
http://www.eclipsesource.com/
========================= Legal Disclaimer =================================
According to Section 80 of the German Corporation Act
Innoopract Informationssysteme GmbH must indicate the following information:
Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
General Manager: Jochen Krause
Registered Office: Commercial Register Mannheim HRB 107883
============================================================================

Re: Create Content-MD5 hash

Posted by Robert Newson <rn...@apache.org>.
try

echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64

as echo includes a new line unless you use -n.

B.

On 27 September 2011 14:29, Moritz Post <mp...@eclipsesource.com> wrote:
> Hallo CouchDB
>
> I am trying to validate the integrity of data i upload to the couchdb.
> Therefore i provide a valid MD5 hash alongside my PUT request. From what i
> have gathered this md5 has to be base64 encoded. My problem is that i am not
> able to create a valid hash. All i get is:
>
> {"error":"content_md5_mismatch","reason":"Possible message corruption."}
>
> I am currently experimenting with a CURL based approach but will need
> to incorporate the hash creation into a java program later. Here is what is
> did do create the md5 hash:
>
> $ md5sum test.json
> 4bf3aac171ded1679d3501ccbd3e0d85  test.json
> $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64
> NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>
> So i have a hash value and now use it in my PUT request (verbose output):
>
> $ curl -X PUT -H "Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK"
> -H "Content-Type: application/json" -v -d @test.json
> http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb
> * About to connect() to 192.168.6.168 port 5984 (#0)
> *   Trying 192.168.6.168... connected
> * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0)
> * Server auth using Basic with user 'admin'
>> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb HTTP/1.1
>> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o
> zlib/1.2.3.4 libidn/1.18
>> Host: 192.168.6.168:5984
>> Accept: */*
>> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK
>> Content-Type: application/json
>> Content-Length: 19
>>
> < HTTP/1.1 400 Bad Request
> < Server: CouchDB/1.0.2 (Erlang OTP/R14B)
> < Date: Tue, 27 Sep 2011 13:23:38 GMT
> < Content-Type: text/plain;charset=utf-8
> < Content-Length: 73
> < Cache-Control: must-revalidate
> <
> {"error":"content_md5_mismatch","reason":"Possible message corruption."}
> * Connection #0 to host 192.168.6.168 left intact
> * Closing connection #0
>
> I am running a couchdb 1.0.3.
>
> The question is: how to properly create a md5 hash that validates the
> upload.
>
> Additionally i would like to know if it is only possible to validated
> attachment uploads or is it also possible to validated the uploaded json
> documents one creates in the couchdb?
>
> Thank you
> Moritz Post
>
> --
> -----------------------------------
> Moritz Post
> EclipseSource
> Email: mpost@eclipsesource.com
> Tel: +49-721-66-47-33-33
> Fax: +49-721-66-47-33-29
> http://www.eclipsesource.com/
> ========================= Legal Disclaimer =================================
> According to Section 80 of the German Corporation Act
> Innoopract Informationssysteme GmbH must indicate the following information:
> Address: Stephanienstrasse 20, 76133 Karlsruhe Germany
> General Manager: Jochen Krause
> Registered Office: Commercial Register Mannheim HRB 107883
> ============================================================================
>