This file is indexed.

/usr/share/doc/python-nacl-doc/html/public.html is in python-nacl-doc 1.0.1-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Public Key Encryption &mdash; PyNaCl 1.0.1 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="PyNaCl 1.0.1 documentation" href="index.html"/>
        <link rel="next" title="Secret Key Encryption" href="secret.html"/>
        <link rel="prev" title="PyNaCl: Python binding to the Networking and Cryptography (NaCl) library" href="index.html"/> 

  
  <script src="_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="index.html" class="icon icon-home"> PyNaCl
          

          
          </a>

          
            
            
              <div class="version">
                10
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="">Public Key Encryption</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#example">Example</a></li>
<li class="toctree-l2"><a class="reference internal" href="#reference">Reference</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="secret.html">Secret Key Encryption</a></li>
<li class="toctree-l1"><a class="reference internal" href="signing.html">Digital Signatures</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="encoding.html">Encoders</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions.html">Exceptions</a></li>
<li class="toctree-l1"><a class="reference internal" href="utils.html">Utility Classes</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="api/hash.html">nacl.hash</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="index.html">PyNaCl</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          





<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="index.html">Docs</a> &raquo;</li>
      
    <li>Public Key Encryption</li>
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="_sources/public.txt" rel="nofollow"> View page source</a>
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="public-key-encryption">
<h1>Public Key Encryption<a class="headerlink" href="#public-key-encryption" title="Permalink to this headline"></a></h1>
<p>Imagine Alice wants something valuable shipped to her. Because it&#8217;s valuable,
she wants to make sure it arrives securely (i.e. hasn&#8217;t been opened or
tampered with) and that it&#8217;s not a forgery (i.e. it&#8217;s actually from the sender
she&#8217;s expecting it to be from and nobody&#8217;s pulling the old switcheroo).</p>
<p>One way she can do this is by providing the sender (let&#8217;s call him Bob) with a
high-security box of her choosing. She provides Bob with this box, and
something else: a padlock, but a padlock without a key. Alice is keeping that
key all to herself. Bob can put items in the box then put the padlock onto it.
But once the padlock snaps shut, the box cannot be opened by anyone who
doesn&#8217;t have Alice&#8217;s private key.</p>
<p>Here&#8217;s the twist though: Bob also puts a padlock onto the box. This padlock
uses a key Bob has published to the world, such that if you have one of Bob&#8217;s
keys, you know a box came from him because Bob&#8217;s keys will open Bob&#8217;s padlocks
(let&#8217;s imagine a world where padlocks cannot be forged even if you know the
key). Bob then sends the box to Alice.</p>
<p>In order for Alice to open the box, she needs two keys: her private key that
opens her own padlock, and Bob&#8217;s well-known key. If Bob&#8217;s key doesn&#8217;t open the
second padlock, then Alice knows that this is not the box she was expecting
from Bob, it&#8217;s a forgery.</p>
<p>This bidirectional guarantee around identity is known as mutual authentication.</p>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline"></a></h2>
<p>The <a class="reference internal" href="#nacl.public.Box" title="nacl.public.Box"><code class="xref py py-class docutils literal"><span class="pre">Box</span></code></a> class uses the given public and private (secret)
keys to derive a shared key, which is used with the nonce given to encrypt the
given messages and to decrypt the given ciphertexts.  The same shared key will
be generated from both pairing of keys, so given two keypairs belonging to
Alice (pkalice, skalice) and Bob (pkbob, skbob), the key derived from
(pkalice, skbob) will equal that from (pkbob, skalice).</p>
<p>This is how the system works:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">nacl.utils</span>
<span class="kn">from</span> <span class="nn">nacl.public</span> <span class="kn">import</span> <span class="n">PrivateKey</span><span class="p">,</span> <span class="n">Box</span>

<span class="c1"># generate the private key which must be kept secret</span>
<span class="n">skbob</span> <span class="o">=</span> <span class="n">PrivateKey</span><span class="o">.</span><span class="n">generate</span><span class="p">()</span>

<span class="c1"># the public key can be given to anyone wishing to send</span>
<span class="c1"># Bob an encrypted message</span>
<span class="n">pkbob</span> <span class="o">=</span> <span class="n">skbob</span><span class="o">.</span><span class="n">public_key</span>

<span class="c1"># Alice does the same and then</span>
<span class="c1">#     sends her public key to Bob and Bob his public key to Alice</span>
<span class="n">skalice</span> <span class="o">=</span> <span class="n">PrivateKey</span><span class="o">.</span><span class="n">generate</span><span class="p">()</span>
<span class="n">pkalice</span> <span class="o">=</span> <span class="n">skalice</span><span class="o">.</span><span class="n">public_key</span>

<span class="c1"># Bob wishes to send Alice an encrypted message</span>
<span class="c1"># So Bob must make a Box with his private key and Alice&#39;s public key</span>
<span class="n">bob_box</span> <span class="o">=</span> <span class="n">Box</span><span class="p">(</span><span class="n">skbob</span><span class="p">,</span> <span class="n">pkalice</span><span class="p">)</span>

<span class="c1"># This is our message to send, it must be a bytestring as Box will</span>
<span class="c1">#   treat is as just a binary blob of data.</span>
<span class="n">message</span> <span class="o">=</span> <span class="n">b</span><span class="s2">&quot;Kill all humans&quot;</span>

<span class="c1"># This is a nonce, it *MUST* only be used once, but it is not considered</span>
<span class="c1">#   secret and can be transmitted or stored alongside the ciphertext. A</span>
<span class="c1">#   good source of nonce is just 24 random bytes.</span>
<span class="n">nonce</span> <span class="o">=</span> <span class="n">nacl</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="n">Box</span><span class="o">.</span><span class="n">NONCE_SIZE</span><span class="p">)</span>

<span class="c1"># Encrypt our message, it will be exactly 40 bytes longer than the original</span>
<span class="c1">#   message as it stores authentication information and nonce alongside it.</span>
<span class="n">encrypted</span> <span class="o">=</span> <span class="n">bob_box</span><span class="o">.</span><span class="n">encrypt</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">nonce</span><span class="p">)</span>

<span class="c1"># Alice creates a second box with her private key to decrypt the message</span>
<span class="n">alice_box</span> <span class="o">=</span> <span class="n">Box</span><span class="p">(</span><span class="n">skalice</span><span class="p">,</span> <span class="n">pkbob</span><span class="p">)</span>

<span class="c1"># Decrypt our message, an exception will be raised if the encryption was</span>
<span class="c1">#   tampered with or there was otherwise an error.</span>
<span class="n">plaintext</span> <span class="o">=</span> <span class="n">alice_box</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">encrypted</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="reference">
<h2>Reference<a class="headerlink" href="#reference" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="nacl.public.PublicKey">
<em class="property">class </em><code class="descclassname">nacl.public.</code><code class="descname">PublicKey</code><span class="sig-paren">(</span><em>public_key</em>, <em>encoder</em><span class="sig-paren">)</span><a class="headerlink" href="#nacl.public.PublicKey" title="Permalink to this definition"></a></dt>
<dd><p>The public key counterpart to an Curve25519
<a class="reference internal" href="#nacl.public.PrivateKey" title="nacl.public.PrivateKey"><code class="xref py py-class docutils literal"><span class="pre">PrivateKey</span></code></a> for encrypting messages.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>public_key</strong> (<em>bytes</em>) &#8211; Encoded Curve25519 public key.</li>
<li><strong>encoder</strong> &#8211; A class that is able to decode the <code class="docutils literal"><span class="pre">public_key</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="class">
<dt id="nacl.public.PrivateKey">
<em class="property">class </em><code class="descclassname">nacl.public.</code><code class="descname">PrivateKey</code><span class="sig-paren">(</span><em>private_key</em>, <em>encoder</em><span class="sig-paren">)</span><a class="headerlink" href="#nacl.public.PrivateKey" title="Permalink to this definition"></a></dt>
<dd><p>Private key for decrypting messages using the Curve25519 algorithm.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">This <strong>must</strong> be protected and remain secret. Anyone who
knows the value of your <a class="reference internal" href="#nacl.public.PrivateKey" title="nacl.public.PrivateKey"><code class="xref py py-class docutils literal"><span class="pre">PrivateKey</span></code></a> can decrypt
any message encrypted by the corresponding
<a class="reference internal" href="#nacl.public.PublicKey" title="nacl.public.PublicKey"><code class="xref py py-class docutils literal"><span class="pre">PublicKey</span></code></a></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>private_key</strong> (<em>bytes</em>) &#8211; The private key used to decrypt messages.</li>
<li><strong>encoder</strong> &#8211; A class that is able to decode the <code class="docutils literal"><span class="pre">private_key</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="nacl.public.PrivateKey.public_key">
<code class="descname">public_key</code><a class="headerlink" href="#nacl.public.PrivateKey.public_key" title="Permalink to this definition"></a></dt>
<dd><p>An instance of <a class="reference internal" href="#nacl.public.PublicKey" title="nacl.public.PublicKey"><code class="xref py py-class docutils literal"><span class="pre">PublicKey</span></code></a> that corresponds with
the private key.</p>
</dd></dl>

<dl class="classmethod">
<dt id="nacl.public.PrivateKey.generate">
<em class="property">classmethod </em><code class="descname">generate</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#nacl.public.PrivateKey.generate" title="Permalink to this definition"></a></dt>
<dd><p>Generates a random <a class="reference internal" href="#nacl.public.PrivateKey" title="nacl.public.PrivateKey"><code class="xref py py-class docutils literal"><span class="pre">PrivateKey</span></code></a> object</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">An instance of <a class="reference internal" href="#nacl.public.PrivateKey" title="nacl.public.PrivateKey"><code class="xref py py-class docutils literal"><span class="pre">PrivateKey</span></code></a>.</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="nacl.public.Box">
<em class="property">class </em><code class="descclassname">nacl.public.</code><code class="descname">Box</code><span class="sig-paren">(</span><em>private_key</em>, <em>public_key</em><span class="sig-paren">)</span><a class="headerlink" href="#nacl.public.Box" title="Permalink to this definition"></a></dt>
<dd><p>The Box class boxes and unboxes messages between a pair of keys</p>
<p>The ciphertexts generated by <a class="reference internal" href="#nacl.public.Box" title="nacl.public.Box"><code class="xref py py-class docutils literal"><span class="pre">Box</span></code></a> include a 16
byte authenticator which is checked as part of the decryption. An invalid
authenticator will cause the decrypt function to raise an exception. The
authenticator is not a signature. Once you&#8217;ve decrypted the message you&#8217;ve
demonstrated the ability to create arbitrary valid message, so messages you
send are repudiable. For non-repudiable messages, sign them after
encryption.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>private_key</strong> &#8211; An instance of <a class="reference internal" href="#nacl.public.PrivateKey" title="nacl.public.PrivateKey"><code class="xref py py-class docutils literal"><span class="pre">PrivateKey</span></code></a> used
to encrypt and decrypt messages</li>
<li><strong>public_key</strong> &#8211; An instance of <a class="reference internal" href="#nacl.public.PublicKey" title="nacl.public.PublicKey"><code class="xref py py-class docutils literal"><span class="pre">PublicKey</span></code></a> used to
encrypt and decrypt messages</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="classmethod">
<dt id="nacl.public.Box.decode">
<em class="property">classmethod </em><code class="descname">decode</code><span class="sig-paren">(</span><em>encoded</em>, <em>encoder</em><span class="sig-paren">)</span><a class="headerlink" href="#nacl.public.Box.decode" title="Permalink to this definition"></a></dt>
<dd><p>Decodes a serialized <a class="reference internal" href="#nacl.public.Box" title="nacl.public.Box"><code class="xref py py-class docutils literal"><span class="pre">Box</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">An instance of <a class="reference internal" href="#nacl.public.Box" title="nacl.public.Box"><code class="xref py py-class docutils literal"><span class="pre">Box</span></code></a>.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="nacl.public.Box.encrypt">
<code class="descname">encrypt</code><span class="sig-paren">(</span><em>plaintext</em>, <em>nonce</em>, <em>encoder</em><span class="sig-paren">)</span><a class="headerlink" href="#nacl.public.Box.encrypt" title="Permalink to this definition"></a></dt>
<dd><p>Encrypts the plaintext message using the given <cite>nonce</cite> and returns
the ciphertext encoded with the encoder.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">It is <strong>VITALLY</strong> important that the nonce is a nonce,
i.e. it is a number used only once for any given key. If you
fail to do this, you compromise the privacy of the messages
encrypted.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>plaintext</strong> (<em>bytes</em>) &#8211; The plaintext message to encrypt.</li>
<li><strong>nonce</strong> (<em>bytes</em>) &#8211; The nonce to use in the encryption.</li>
<li><strong>encoder</strong> &#8211; A class that is able to decode the ciphertext.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">An instance of <code class="xref py py-class docutils literal"><span class="pre">EncryptedMessage</span></code>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="nacl.public.Box.decrypt">
<code class="descname">decrypt</code><span class="sig-paren">(</span><em>ciphertext</em>, <em>nonce</em>, <em>encoder</em><span class="sig-paren">)</span><a class="headerlink" href="#nacl.public.Box.decrypt" title="Permalink to this definition"></a></dt>
<dd><p>Decrypts the ciphertext using the given nonce and returns the
plaintext message.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>ciphertext</strong> (<em>bytes</em>) &#8211; The encrypted message to decrypt.</li>
<li><strong>nonce</strong> (<em>bytes</em>) &#8211; The nonce to use in the decryption.</li>
<li><strong>encoder</strong> &#8211; A class that is able to decode the plaintext.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Return bytes:</th><td class="field-body"><p class="first last">The decrypted plaintext.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
</div>


           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="secret.html" class="btn btn-neutral float-right" title="Secret Key Encryption" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="index.html" class="btn btn-neutral" title="PyNaCl: Python binding to the Networking and Cryptography (NaCl) library" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2013, Donald Stufft and Individual Contributors.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'./',
            VERSION:'1.0.1',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="_static/jquery.js"></script>
      <script type="text/javascript" src="_static/underscore.js"></script>
      <script type="text/javascript" src="_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>