PageRenderTime 24ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

HTML | 76 lines | 71 code | 1 blank | 4 comment | 0 complexity | deaf447fff8f05e2c102c0a607a0eb46 MD5 | raw file
 1<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><!-- DW6 -->
 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">
 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>: 
14outmd5 </p>
16<pre class="lang">#include &lt;pstreams.h&gt;
18class outmd5: outstm {
19    outmd5();
20    outmd5(outstm* outthru);
21    string get_digest();
22    const unsigned char* get_bindigest();
26<p>MD5, the message digest algorithm described in RFC 1321, computes a 128-bit 
27sequence (sometimes called 'message digest', 'fingerprint' or 'MD5 checksum') 
28from arbitrary data. As stated in RFC 1321, it is conjectured that it is computationally 
29infeasible to produce two messages having the same message digest, or to produce 
30any message having a given prespecified target message digest. MD5 can be viewed 
31as a one-way encryption system and can be used, for example, to encrypt passwords 
32in a password database.</p>
33<p>The MD5 fingerprint is more often converted to so-called ASCII-64 form in order 
34to conveniently store it in plain text environments and protocols. Thus, the 128-bit 
35binary sequence becomes a 22-character text string consisting of letters, digits 
36and two special symbols '.' and '/'. (Note that this is not the same as Base64 
37encoding in MIME).</p>
38<p>In order to compute a MD5 fingerprint you first create a stream object of type 
39<span class="lang">outmd5</span> and then send data to it as if it was an ordinary 
40output file or a socket stream. After you close the stream, you can obtain the 
41fingerprint in ASCII-64 form using the object's <span class="lang">get_digest()</span> 
43<p>The implementation of MD5 is derived from L. Peter Deutsch's work.</p>
44<p>This class derives all public methods and properties from <a href="streams.iobase.html">iobase</a> 
45and <a href="streams.outstm.html">outstm</a>, and in addition defines the following:</p>
46<p><span class="def">outmd5::outmd5()</span> creates a bufferless MD5 stream.</p>
47<p><span class="def">outmd5::outmd5(outstm* outthru)</span> creates a MD5 stream 
48and attaches an output stream <span class="lang">outthru</span> to it. Everything 
49sent to the MD5 stream will also be duplicated to <span class="lang">outthru</span>. 
50You may want, for example, to attach <span class="lang">perr</span> to your MD5 
51stream for debugging purposes.</p>
52<p><span class="def">string outmd5::get_digest()</span> closes the stream and 
53returns the computed fingerprint in text form (ASCII-64).</p>
54<p><span class="def">const unsigned char* outmd5::get_bindigest()</span> closes 
55the stream and returns a pointer to a 16-byte buffer with the binary MD5 fingerprint.</p>
59string cryptpw(string username, string password)
61    outmd5 m;
63    m.put(username);
64    m.put(password);
65    m.put(&quot;Banana with ketchup&quot;);
66    return m.get_digest();
70<p class="seealso">See also: <a href="streams.iobase.html">iobase</a>, <a href="streams.outstm.html">outstm</a> 
72<!-- #EndEditable -->
73<hr size="1">
74<a href="../index.html" class="ns">PTypes home</a>
76<!-- #EndTemplate --></html>