/doc/streams.md5.html

http://github.com/foodmike/PTypes · HTML · 76 lines · 71 code · 1 blank · 4 comment · 0 complexity · deaf447fff8f05e2c102c0a607a0eb46 MD5 · raw file

  1. <html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><!-- DW6 -->
  2. <head>
  3. <!-- #BeginEditable "doctitle" -->
  4. <title>PTypes: streams: outmd5</title>
  5. <!-- #EndEditable -->
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  7. <link rel="stylesheet" href="styles.css">
  8. </head>
  9. <body bgcolor="#FFFFFF" leftmargin="40" marginwidth="40">
  10. <p><a href="../index.html"><img src="title-21.png" width="253" height="39" alt="C++ Portable Types Library (PTypes) Version 2.1" border="0"></a>
  11. <hr size="1" noshade>
  12. <!-- #BeginEditable "body" -->
  13. <p class="hpath"><a href="index.html">Top</a>: <a href="streams.html">Streams</a>:
  14. outmd5 </p>
  15. <blockquote>
  16. <pre class="lang">#include &lt;pstreams.h&gt;
  17. class outmd5: outstm {
  18. outmd5();
  19. outmd5(outstm* outthru);
  20. string get_digest();
  21. const unsigned char* get_bindigest();
  22. }
  23. </pre>
  24. </blockquote>
  25. <p>MD5, the message digest algorithm described in RFC 1321, computes a 128-bit
  26. sequence (sometimes called 'message digest', 'fingerprint' or 'MD5 checksum')
  27. from arbitrary data. As stated in RFC 1321, it is conjectured that it is computationally
  28. infeasible to produce two messages having the same message digest, or to produce
  29. any message having a given prespecified target message digest. MD5 can be viewed
  30. as a one-way encryption system and can be used, for example, to encrypt passwords
  31. in a password database.</p>
  32. <p>The MD5 fingerprint is more often converted to so-called ASCII-64 form in order
  33. to conveniently store it in plain text environments and protocols. Thus, the 128-bit
  34. binary sequence becomes a 22-character text string consisting of letters, digits
  35. and two special symbols '.' and '/'. (Note that this is not the same as Base64
  36. encoding in MIME).</p>
  37. <p>In order to compute a MD5 fingerprint you first create a stream object of type
  38. <span class="lang">outmd5</span> and then send data to it as if it was an ordinary
  39. output file or a socket stream. After you close the stream, you can obtain the
  40. fingerprint in ASCII-64 form using the object's <span class="lang">get_digest()</span>
  41. method.</p>
  42. <p>The implementation of MD5 is derived from L. Peter Deutsch's work.</p>
  43. <p>This class derives all public methods and properties from <a href="streams.iobase.html">iobase</a>
  44. and <a href="streams.outstm.html">outstm</a>, and in addition defines the following:</p>
  45. <p><span class="def">outmd5::outmd5()</span> creates a bufferless MD5 stream.</p>
  46. <p><span class="def">outmd5::outmd5(outstm* outthru)</span> creates a MD5 stream
  47. and attaches an output stream <span class="lang">outthru</span> to it. Everything
  48. sent to the MD5 stream will also be duplicated to <span class="lang">outthru</span>.
  49. You may want, for example, to attach <span class="lang">perr</span> to your MD5
  50. stream for debugging purposes.</p>
  51. <p><span class="def">string outmd5::get_digest()</span> closes the stream and
  52. returns the computed fingerprint in text form (ASCII-64).</p>
  53. <p><span class="def">const unsigned char* outmd5::get_bindigest()</span> closes
  54. the stream and returns a pointer to a 16-byte buffer with the binary MD5 fingerprint.</p>
  55. <p><b>Example:</b></p>
  56. <blockquote>
  57. <pre>
  58. string cryptpw(string username, string password)
  59. {
  60. outmd5 m;
  61. m.open();
  62. m.put(username);
  63. m.put(password);
  64. m.put(&quot;Banana with ketchup&quot;);
  65. return m.get_digest();
  66. }
  67. </pre>
  68. </blockquote>
  69. <p class="seealso">See also: <a href="streams.iobase.html">iobase</a>, <a href="streams.outstm.html">outstm</a>
  70. </p>
  71. <!-- #EndEditable -->
  72. <hr size="1">
  73. <a href="../index.html" class="ns">PTypes home</a>
  74. </body>
  75. <!-- #EndTemplate --></html>