Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > 64656f00434e190abe8506174ca339ed > files > 8

ucommon-doc-4.3.1-1.mga1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>ucommon: cipher.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">ucommon</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00006.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>cipher.cpp</h1>  </div>
</div>
<div class="contents">
<p>Example of cipher code.</p>
<div class="fragment"><pre class="fragment"><span class="comment">// Copyright (C) 2006-2010 David Sugar, Tycho Softworks.</span>
<span class="comment">//</span>
<span class="comment">// This file is part of GNU uCommon C++.</span>
<span class="comment">//</span>
<span class="comment">// GNU uCommon C++ is free software: you can redistribute it and/or modify</span>
<span class="comment">// it under the terms of the GNU Lesser General Public License as published</span>
<span class="comment">// by the Free Software Foundation, either version 3 of the License, or</span>
<span class="comment">// (at your option) any later version.</span>
<span class="comment">//</span>
<span class="comment">// GNU uCommon C++ is distributed in the hope that it will be useful,</span>
<span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment">// GNU Lesser General Public License for more details.</span>
<span class="comment">//</span>
<span class="comment">// You should have received a copy of the GNU Lesser General Public License</span>
<span class="comment">// along with GNU uCommon C++.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>

<span class="preprocessor">#ifndef DEBUG</span>
<span class="preprocessor"></span><span class="preprocessor">#define DEBUG</span>
<span class="preprocessor"></span><span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="preprocessor">#include &lt;config.h&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="a00195.html" title="This library holds basic cryptographic functions and secure socket support for use with GNU uCommon C...">ucommon/secure.h</a>&gt;</span>

<span class="preprocessor">#include &lt;stdio.h&gt;</span>

<span class="keyword">using namespace </span>UCOMMON_NAMESPACE;
<span class="keyword">using namespace </span>std;

<span class="preprocessor">#define STR &quot;this is a test of some text we wish to post&quot;</span>
<span class="preprocessor"></span>
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
    <span class="keywordflow">if</span>(!<a name="a0"></a><a class="code" href="a00119.html#ada0af1c61b17a135c90564d8158d93e4" title="Initialize secure stack for first use, and report if SSL support is compiled in.">secure::init</a>())
        <span class="keywordflow">return</span> 0;

    <a name="_a1"></a><a class="code" href="a00033.html" title="Cipher key formed by hash algorithm.">skey_t</a> mykey(<span class="stringliteral">&quot;aes256&quot;</span>, <span class="stringliteral">&quot;sha&quot;</span>, <span class="stringliteral">&quot;testing&quot;</span>);
    <a name="_a2"></a><a class="code" href="a00032.html" title="A generic data ciphering class.">cipher_t</a> enc, dec;
    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ebuf[256], dbuf[256];

    memset(dbuf, 0, <span class="keyword">sizeof</span>(dbuf));

    enc.<a name="a3"></a>set(&amp;mykey, Cipher::ENCRYPT, ebuf);
    dec.set(&amp;mykey, Cipher::DECRYPT, dbuf);

    <span class="keywordtype">size_t</span> total = enc.<a name="a4"></a><a class="code" href="a00032.html#afa68f2d96556e5e7a7a4b98a60e3440a" title="This essentially encrypts a single string and pads with NULL bytes as needed.">puts</a>(STR);

    assert(!<a name="a5"></a><a class="code" href="a00197.html#a980d221b0273a9bf5d14a0f403495b40" title="Compare two socket addresses to see if equal.">eq</a>(STR, (<span class="keywordtype">char</span> *)ebuf, strlen(STR)));

    assert(total == 48);

    dec.<a name="a6"></a><a class="code" href="a00032.html#ac42c3de43f0377ae36e7c3b8d2ce5807" title="Process cipher data.">put</a>(ebuf, total);
    dec.<a name="a7"></a><a class="code" href="a00032.html#a0400ea6f5c3599183d220cec8edbc44e" title="Push a final cipher block.">flush</a>();
    assert(<a class="code" href="a00197.html#a980d221b0273a9bf5d14a0f403495b40" title="Compare two socket addresses to see if equal.">eq</a>((<span class="keywordtype">char</span> *)dbuf, STR));
    <span class="keywordflow">return</span> 0;
}

</pre></div> </div>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="footer">Generated on Wed Apr 13 2011 22:39:47 for ucommon by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li>
    </ul>
  </div>

</body>
</html>