Documentation/Source/eric5.Utilities.crypto.py3AES.html

changeset 1127
b1802ebe0066
child 1228
7afaf2fca55b
equal deleted inserted replaced
1123:4ed80ed7e433 1127:b1802ebe0066
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
3 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
4 <html><head>
5 <title>eric5.Utilities.crypto.py3AES</title>
6 <style>
7 body {
8 background: #EDECE6;
9 margin: 0em 1em 10em 1em;
10 color: black;
11 }
12
13 h1 { color: white; background: #85774A; }
14 h2 { color: white; background: #85774A; }
15 h3 { color: white; background: #9D936E; }
16 h4 { color: white; background: #9D936E; }
17
18 a { color: #BA6D36; }
19
20 </style>
21 </head>
22 <body><a NAME="top" ID="top"></a>
23 <h1>eric5.Utilities.crypto.py3AES</h1>
24 <p>
25 Module implementing classes for encryption according
26 Advanced Encryption Standard.
27 </p>
28 <h3>Global Attributes</h3>
29 <table>
30 <tr><td>None</td></tr>
31 </table>
32 <h3>Classes</h3>
33 <table>
34 <tr>
35 <td><a href="#AES">AES</a></td>
36 <td>Class implementing the Advanced Encryption Standard algorithm.</td>
37 </tr><tr>
38 <td><a href="#AESModeOfOperation">AESModeOfOperation</a></td>
39 <td>Class implementing the different AES mode of operations.</td>
40 </tr>
41 </table>
42 <h3>Functions</h3>
43 <table>
44 <tr>
45 <td><a href="#append_PKCS7_padding">append_PKCS7_padding</a></td>
46 <td>Function to pad the given data to a multiple of 16-bytes by PKCS7 padding.</td>
47 </tr><tr>
48 <td><a href="#decryptData">decryptData</a></td>
49 <td>Module function to decrypt the given data with the given key.</td>
50 </tr><tr>
51 <td><a href="#encryptData">encryptData</a></td>
52 <td>Module function to encrypt the given data with the given key.</td>
53 </tr><tr>
54 <td><a href="#strip_PKCS7_padding">strip_PKCS7_padding</a></td>
55 <td>Function to strip off PKCS7 padding.</td>
56 </tr>
57 </table>
58 <hr /><hr />
59 <a NAME="AES" ID="AES"></a>
60 <h2>AES</h2>
61 <p>
62 Class implementing the Advanced Encryption Standard algorithm.
63 </p>
64 <h3>Derived from</h3>
65 object
66 <h3>Class Attributes</h3>
67 <table>
68 <tr><td>KeySize</td></tr><tr><td>Rcon</td></tr><tr><td>rsbox</td></tr><tr><td>sbox</td></tr>
69 </table>
70 <h3>Methods</h3>
71 <table>
72 <tr>
73 <td><a href="#AES.__addRoundKey">__addRoundKey</a></td>
74 <td>Private method to add (XORs) the round key to the state.</td>
75 </tr><tr>
76 <td><a href="#AES.__aes_invMain">__aes_invMain</a></td>
77 <td>Private method to perform the initial operations, the standard round, and the final operations of the inverse AES, creating a round key for each round.</td>
78 </tr><tr>
79 <td><a href="#AES.__aes_invRound">__aes_invRound</a></td>
80 <td>Private method to apply the 4 operations of the inverse round in sequence.</td>
81 </tr><tr>
82 <td><a href="#AES.__aes_main">__aes_main</a></td>
83 <td>Private method to perform the initial operations, the standard round, and the final operations of the forward AES, creating a round key for each round.</td>
84 </tr><tr>
85 <td><a href="#AES.__aes_round">__aes_round</a></td>
86 <td>Private method to apply the 4 operations of the forward round in sequence.</td>
87 </tr><tr>
88 <td><a href="#AES.__core">__core</a></td>
89 <td>Private method performing the key schedule core operation.</td>
90 </tr><tr>
91 <td><a href="#AES.__createRoundKey">__createRoundKey</a></td>
92 <td>Private method to create a round key.</td>
93 </tr><tr>
94 <td><a href="#AES.__expandKey">__expandKey</a></td>
95 <td>Private method performing Rijndael's key expansion.</td>
96 </tr><tr>
97 <td><a href="#AES.__galois_multiplication">__galois_multiplication</a></td>
98 <td>Private method to perform a Galois multiplication of 8 bit characters a and b.</td>
99 </tr><tr>
100 <td><a href="#AES.__getRconValue">__getRconValue</a></td>
101 <td>Private method to retrieve a given Rcon value.</td>
102 </tr><tr>
103 <td><a href="#AES.__getSBoxInvert">__getSBoxInvert</a></td>
104 <td>Private method to retrieve a given Inverted S-Box value.</td>
105 </tr><tr>
106 <td><a href="#AES.__getSBoxValue">__getSBoxValue</a></td>
107 <td>Private method to retrieve a given S-Box value.</td>
108 </tr><tr>
109 <td><a href="#AES.__mixColumn">__mixColumn</a></td>
110 <td>Private method to perform a galois multiplication of 1 column the 4x4 matrix.</td>
111 </tr><tr>
112 <td><a href="#AES.__mixColumns">__mixColumns</a></td>
113 <td>Private method to perform a galois multiplication of the 4x4 matrix.</td>
114 </tr><tr>
115 <td><a href="#AES.__rotate">__rotate</a></td>
116 <td>Private method performing Rijndael's key schedule rotate operation.</td>
117 </tr><tr>
118 <td><a href="#AES.__shiftRow">__shiftRow</a></td>
119 <td>Private method to shift the bytes of a row to the left.</td>
120 </tr><tr>
121 <td><a href="#AES.__shiftRows">__shiftRows</a></td>
122 <td>Private method to iterate over the 4 rows and call __shiftRow() with that row.</td>
123 </tr><tr>
124 <td><a href="#AES.__subBytes">__subBytes</a></td>
125 <td>Private method to substitute all the values from the state with the value in the SBox using the state value as index for the SBox.</td>
126 </tr><tr>
127 <td><a href="#AES.decrypt">decrypt</a></td>
128 <td>Public method to decrypt a 128 bit input block against the given key of size specified.</td>
129 </tr><tr>
130 <td><a href="#AES.encrypt">encrypt</a></td>
131 <td>Public method to encrypt a 128 bit input block against the given key of size specified.</td>
132 </tr>
133 </table>
134 <a NAME="AES.__addRoundKey" ID="AES.__addRoundKey"></a>
135 <h4>AES.__addRoundKey</h4>
136 <b>__addRoundKey</b>(<i>state, roundKey</i>)
137 <p>
138 Private method to add (XORs) the round key to the state.
139 </p><dl>
140 <dt><i>state</i></dt>
141 <dd>
142 state to be changed (bytearray)
143 </dd><dt><i>roundKey</i></dt>
144 <dd>
145 key to be used for the modification (bytearray)
146 </dd>
147 </dl><dl>
148 <dt>Returns:</dt>
149 <dd>
150 modified state (bytearray)
151 </dd>
152 </dl><a NAME="AES.__aes_invMain" ID="AES.__aes_invMain"></a>
153 <h4>AES.__aes_invMain</h4>
154 <b>__aes_invMain</b>(<i>state, expandedKey, nbrRounds</i>)
155 <p>
156 Private method to perform the initial operations, the standard round, and the
157 final operations of the inverse AES, creating a round key for each round.
158 </p><dl>
159 <dt><i>state</i></dt>
160 <dd>
161 state to be worked on (bytearray)
162 </dd><dt><i>expandedKey</i></dt>
163 <dd>
164 expanded key to be used (bytearray)
165 </dd><dt><i>nbrRounds</i></dt>
166 <dd>
167 number of rounds to be done (integer)
168 </dd>
169 </dl><dl>
170 <dt>Returns:</dt>
171 <dd>
172 modified state (bytearray)
173 </dd>
174 </dl><a NAME="AES.__aes_invRound" ID="AES.__aes_invRound"></a>
175 <h4>AES.__aes_invRound</h4>
176 <b>__aes_invRound</b>(<i>state, roundKey</i>)
177 <p>
178 Private method to apply the 4 operations of the inverse round in sequence.
179 </p><dl>
180 <dt><i>state</i></dt>
181 <dd>
182 state to be worked on (bytearray)
183 </dd><dt><i>roundKey</i></dt>
184 <dd>
185 round key to be used (bytearray)
186 </dd>
187 </dl><dl>
188 <dt>Returns:</dt>
189 <dd>
190 modified state (bytearray)
191 </dd>
192 </dl><a NAME="AES.__aes_main" ID="AES.__aes_main"></a>
193 <h4>AES.__aes_main</h4>
194 <b>__aes_main</b>(<i>state, expandedKey, nbrRounds</i>)
195 <p>
196 Private method to perform the initial operations, the standard round, and the
197 final operations of the forward AES, creating a round key for each round.
198 </p><dl>
199 <dt><i>state</i></dt>
200 <dd>
201 state to be worked on (bytearray)
202 </dd><dt><i>expandedKey</i></dt>
203 <dd>
204 expanded key to be used (bytearray)
205 </dd><dt><i>nbrRounds</i></dt>
206 <dd>
207 number of rounds to be done (integer)
208 </dd>
209 </dl><dl>
210 <dt>Returns:</dt>
211 <dd>
212 modified state (bytearray)
213 </dd>
214 </dl><a NAME="AES.__aes_round" ID="AES.__aes_round"></a>
215 <h4>AES.__aes_round</h4>
216 <b>__aes_round</b>(<i>state, roundKey</i>)
217 <p>
218 Private method to apply the 4 operations of the forward round in sequence.
219 </p><dl>
220 <dt><i>state</i></dt>
221 <dd>
222 state to be worked on (bytearray)
223 </dd><dt><i>roundKey</i></dt>
224 <dd>
225 round key to be used (bytearray)
226 </dd>
227 </dl><dl>
228 <dt>Returns:</dt>
229 <dd>
230 modified state (bytearray)
231 </dd>
232 </dl><a NAME="AES.__core" ID="AES.__core"></a>
233 <h4>AES.__core</h4>
234 <b>__core</b>(<i>data, iteration</i>)
235 <p>
236 Private method performing the key schedule core operation.
237 </p><dl>
238 <dt><i>data</i></dt>
239 <dd>
240 data to operate on (bytearray)
241 </dd><dt><i>iteration</i></dt>
242 <dd>
243 iteration counter (integer)
244 </dd>
245 </dl><dl>
246 <dt>Returns:</dt>
247 <dd>
248 modified data (bytearray)
249 </dd>
250 </dl><a NAME="AES.__createRoundKey" ID="AES.__createRoundKey"></a>
251 <h4>AES.__createRoundKey</h4>
252 <b>__createRoundKey</b>(<i>expandedKey, roundKeyPointer</i>)
253 <p>
254 Private method to create a round key.
255 </p><dl>
256 <dt><i>expandedKey</i></dt>
257 <dd>
258 expanded key to be used (bytearray)
259 </dd><dt><i>roundKeyPointer</i></dt>
260 <dd>
261 position within the expanded key (integer)
262 </dd>
263 </dl><dl>
264 <dt>Returns:</dt>
265 <dd>
266 round key (bytearray)
267 </dd>
268 </dl><a NAME="AES.__expandKey" ID="AES.__expandKey"></a>
269 <h4>AES.__expandKey</h4>
270 <b>__expandKey</b>(<i>key, size, expandedKeySize</i>)
271 <p>
272 Private method performing Rijndael's key expansion.
273 </p><p>
274 Expands a 128, 192 or 256 bit key into a 176, 208 or 240 bit key.
275 </p><dl>
276 <dt><i>key</i></dt>
277 <dd>
278 key to be expanded (bytes or bytearray)
279 </dd><dt><i>size</i></dt>
280 <dd>
281 size of the key in bytes (16, 24 or 32)
282 </dd><dt><i>expandedKeySize</i></dt>
283 <dd>
284 size of the expanded key (integer)
285 </dd>
286 </dl><dl>
287 <dt>Returns:</dt>
288 <dd>
289 expanded key (bytearray)
290 </dd>
291 </dl><a NAME="AES.__galois_multiplication" ID="AES.__galois_multiplication"></a>
292 <h4>AES.__galois_multiplication</h4>
293 <b>__galois_multiplication</b>(<i>a, b</i>)
294 <p>
295 Private method to perform a Galois multiplication of 8 bit characters a and b.
296 </p><dl>
297 <dt><i>a</i></dt>
298 <dd>
299 first factor (byte)
300 </dd><dt><i>b</i></dt>
301 <dd>
302 second factor (byte)
303 </dd>
304 </dl><dl>
305 <dt>Returns:</dt>
306 <dd>
307 result (byte)
308 </dd>
309 </dl><a NAME="AES.__getRconValue" ID="AES.__getRconValue"></a>
310 <h4>AES.__getRconValue</h4>
311 <b>__getRconValue</b>(<i>num</i>)
312 <p>
313 Private method to retrieve a given Rcon value.
314 </p><dl>
315 <dt><i>num</i></dt>
316 <dd>
317 position of the value (integer)
318 </dd>
319 </dl><dl>
320 <dt>Returns:</dt>
321 <dd>
322 Rcon value (integer)
323 </dd>
324 </dl><a NAME="AES.__getSBoxInvert" ID="AES.__getSBoxInvert"></a>
325 <h4>AES.__getSBoxInvert</h4>
326 <b>__getSBoxInvert</b>(<i>num</i>)
327 <p>
328 Private method to retrieve a given Inverted S-Box value.
329 </p><dl>
330 <dt><i>num</i></dt>
331 <dd>
332 position of the value (integer)
333 </dd>
334 </dl><dl>
335 <dt>Returns:</dt>
336 <dd>
337 value of the Inverted S-Box (integer)
338 </dd>
339 </dl><a NAME="AES.__getSBoxValue" ID="AES.__getSBoxValue"></a>
340 <h4>AES.__getSBoxValue</h4>
341 <b>__getSBoxValue</b>(<i>num</i>)
342 <p>
343 Private method to retrieve a given S-Box value.
344 </p><dl>
345 <dt><i>num</i></dt>
346 <dd>
347 position of the value (integer)
348 </dd>
349 </dl><dl>
350 <dt>Returns:</dt>
351 <dd>
352 value of the S-Box (integer)
353 </dd>
354 </dl><a NAME="AES.__mixColumn" ID="AES.__mixColumn"></a>
355 <h4>AES.__mixColumn</h4>
356 <b>__mixColumn</b>(<i>column, isInv</i>)
357 <p>
358 Private method to perform a galois multiplication of 1 column the 4x4 matrix.
359 </p><dl>
360 <dt><i>column</i></dt>
361 <dd>
362 column to be worked on (bytearray)
363 </dd><dt><i>isInv</i></dt>
364 <dd>
365 flag indicating an inverse operation (boolean)
366 </dd>
367 </dl><dl>
368 <dt>Returns:</dt>
369 <dd>
370 modified column (bytearray)
371 </dd>
372 </dl><a NAME="AES.__mixColumns" ID="AES.__mixColumns"></a>
373 <h4>AES.__mixColumns</h4>
374 <b>__mixColumns</b>(<i>state, isInv</i>)
375 <p>
376 Private method to perform a galois multiplication of the 4x4 matrix.
377 </p><dl>
378 <dt><i>state</i></dt>
379 <dd>
380 state to be worked on (bytearray)
381 </dd><dt><i>isInv</i></dt>
382 <dd>
383 flag indicating an inverse operation (boolean)
384 </dd>
385 </dl><dl>
386 <dt>Returns:</dt>
387 <dd>
388 modified state (bytearray)
389 </dd>
390 </dl><a NAME="AES.__rotate" ID="AES.__rotate"></a>
391 <h4>AES.__rotate</h4>
392 <b>__rotate</b>(<i>data</i>)
393 <p>
394 Private method performing Rijndael's key schedule rotate operation.
395 </p><p>
396 Rotate the data word eight bits to the left: eg, rotate(1d2c3a4f) == 2c3a4f1d.
397 </p><dl>
398 <dt><i>data</i></dt>
399 <dd>
400 data of size 4 (bytearray)
401 </dd>
402 </dl><a NAME="AES.__shiftRow" ID="AES.__shiftRow"></a>
403 <h4>AES.__shiftRow</h4>
404 <b>__shiftRow</b>(<i>state, statePointer, nbr, isInv</i>)
405 <p>
406 Private method to shift the bytes of a row to the left.
407 </p><dl>
408 <dt><i>state</i></dt>
409 <dd>
410 state to be worked on (bytearray)
411 </dd><dt><i>statePointer</i></dt>
412 <dd>
413 index into the state (integer)
414 </dd><dt><i>nbr</i></dt>
415 <dd>
416 number of positions to shift (integer)
417 </dd><dt><i>isInv</i></dt>
418 <dd>
419 flag indicating an inverse operation (boolean)
420 </dd>
421 </dl><dl>
422 <dt>Returns:</dt>
423 <dd>
424 modified state (bytearray)
425 </dd>
426 </dl><a NAME="AES.__shiftRows" ID="AES.__shiftRows"></a>
427 <h4>AES.__shiftRows</h4>
428 <b>__shiftRows</b>(<i>state, isInv</i>)
429 <p>
430 Private method to iterate over the 4 rows and call __shiftRow() with
431 that row.
432 </p><dl>
433 <dt><i>state</i></dt>
434 <dd>
435 state to be worked on (bytearray)
436 </dd><dt><i>isInv</i></dt>
437 <dd>
438 flag indicating an inverse operation (boolean)
439 </dd>
440 </dl><dl>
441 <dt>Returns:</dt>
442 <dd>
443 modified state (bytearray)
444 </dd>
445 </dl><a NAME="AES.__subBytes" ID="AES.__subBytes"></a>
446 <h4>AES.__subBytes</h4>
447 <b>__subBytes</b>(<i>state, isInv</i>)
448 <p>
449 Private method to substitute all the values from the state with the value in
450 the SBox using the state value as index for the SBox.
451 </p><dl>
452 <dt><i>state</i></dt>
453 <dd>
454 state to be worked on (bytearray)
455 </dd><dt><i>isInv</i></dt>
456 <dd>
457 flag indicating an inverse operation (boolean)
458 </dd>
459 </dl><dl>
460 <dt>Returns:</dt>
461 <dd>
462 modified state (bytearray)
463 </dd>
464 </dl><a NAME="AES.decrypt" ID="AES.decrypt"></a>
465 <h4>AES.decrypt</h4>
466 <b>decrypt</b>(<i>iput, key, size</i>)
467 <p>
468 Public method to decrypt a 128 bit input block against the given key of size
469 specified.
470 </p><dl>
471 <dt><i>iput</i></dt>
472 <dd>
473 input data (bytearray)
474 </dd><dt><i>key</i></dt>
475 <dd>
476 key to be used (bytes or bytearray)
477 </dd><dt><i>size</i></dt>
478 <dd>
479 key size (16, 24 or 32)
480 </dd>
481 </dl><dl>
482 <dt>Returns:</dt>
483 <dd>
484 decrypted data (bytes)
485 </dd>
486 </dl><a NAME="AES.encrypt" ID="AES.encrypt"></a>
487 <h4>AES.encrypt</h4>
488 <b>encrypt</b>(<i>iput, key, size</i>)
489 <p>
490 Public method to encrypt a 128 bit input block against the given key of size
491 specified.
492 </p><dl>
493 <dt><i>iput</i></dt>
494 <dd>
495 input data (bytearray)
496 </dd><dt><i>key</i></dt>
497 <dd>
498 key to be used (bytes or bytearray)
499 </dd><dt><i>size</i></dt>
500 <dd>
501 key size (16, 24 or 32)
502 </dd>
503 </dl><dl>
504 <dt>Returns:</dt>
505 <dd>
506 encrypted data (bytes)
507 </dd>
508 </dl>
509 <div align="right"><a href="#top">Up</a></div>
510 <hr /><hr />
511 <a NAME="AESModeOfOperation" ID="AESModeOfOperation"></a>
512 <h2>AESModeOfOperation</h2>
513 <p>
514 Class implementing the different AES mode of operations.
515 </p>
516 <h3>Derived from</h3>
517 object
518 <h3>Class Attributes</h3>
519 <table>
520 <tr><td>ModeOfOperation</td></tr><tr><td>aes</td></tr>
521 </table>
522 <h3>Methods</h3>
523 <table>
524 <tr>
525 <td><a href="#AESModeOfOperation.__extractBytes">__extractBytes</a></td>
526 <td>Private method to extract a range of bytes from the input.</td>
527 </tr><tr>
528 <td><a href="#AESModeOfOperation.decrypt">decrypt</a></td>
529 <td>Public method to perform the decryption operation.</td>
530 </tr><tr>
531 <td><a href="#AESModeOfOperation.encrypt">encrypt</a></td>
532 <td>Public method to perform the encryption operation.</td>
533 </tr>
534 </table>
535 <a NAME="AESModeOfOperation.__extractBytes" ID="AESModeOfOperation.__extractBytes"></a>
536 <h4>AESModeOfOperation.__extractBytes</h4>
537 <b>__extractBytes</b>(<i>input, start, end, mode</i>)
538 <p>
539 Private method to extract a range of bytes from the input.
540 </p><dl>
541 <dt><i>input</i></dt>
542 <dd>
543 input data (bytes)
544 </dd><dt><i>start</i></dt>
545 <dd>
546 start index (integer)
547 </dd><dt><i>end</i></dt>
548 <dd>
549 end index (integer)
550 </dd><dt><i>mode</i></dt>
551 <dd>
552 mode of operation (0, 1, 2)
553 </dd>
554 </dl><dl>
555 <dt>Returns:</dt>
556 <dd>
557 extracted bytes (bytearray)
558 </dd>
559 </dl><a NAME="AESModeOfOperation.decrypt" ID="AESModeOfOperation.decrypt"></a>
560 <h4>AESModeOfOperation.decrypt</h4>
561 <b>decrypt</b>(<i>cipherIn, originalsize, mode, key, size, IV</i>)
562 <p>
563 Public method to perform the decryption operation.
564 </p><dl>
565 <dt><i>input</i></dt>
566 <dd>
567 data to be encrypted (bytes)
568 </dd><dt><i>originalsize</i></dt>
569 <dd>
570 unencrypted string length (required for CBC)
571 (integer)
572 </dd><dt><i>mode</i></dt>
573 <dd>
574 mode of operation (0, 1 or 2)
575 </dd><dt><i>key</i></dt>
576 <dd>
577 key to be used (bytes)
578 </dd><dt><i>size</i></dt>
579 <dd>
580 length of the key (integer)
581 </dd><dt><i>IV</i></dt>
582 <dd>
583 initialisation vector (bytearray)
584 </dd>
585 </dl><dl>
586 <dt>Returns:</dt>
587 <dd>
588 decrypted data (bytes)
589 </dd>
590 </dl><a NAME="AESModeOfOperation.encrypt" ID="AESModeOfOperation.encrypt"></a>
591 <h4>AESModeOfOperation.encrypt</h4>
592 <b>encrypt</b>(<i>input, mode, key, size, IV</i>)
593 <p>
594 Public method to perform the encryption operation.
595 </p><dl>
596 <dt><i>input</i></dt>
597 <dd>
598 data to be encrypted (bytes)
599 </dd><dt><i>mode</i></dt>
600 <dd>
601 mode of operation (0, 1 or 2)
602 </dd><dt><i>key</i></dt>
603 <dd>
604 key to be used (bytes)
605 </dd><dt><i>size</i></dt>
606 <dd>
607 length of the key (integer)
608 </dd><dt><i>IV</i></dt>
609 <dd>
610 initialisation vector (bytearray)
611 </dd>
612 </dl><dl>
613 <dt>Returns:</dt>
614 <dd>
615 tuple with mode of operation, length of the input and
616 the encrypted data (integer, integer, bytes)
617 </dd>
618 </dl>
619 <div align="right"><a href="#top">Up</a></div>
620 <hr /><hr />
621 <a NAME="append_PKCS7_padding" ID="append_PKCS7_padding"></a>
622 <h2>append_PKCS7_padding</h2>
623 <b>append_PKCS7_padding</b>(<i>b</i>)
624 <p>
625 Function to pad the given data to a multiple of 16-bytes by PKCS7 padding.
626 </p><dl>
627 <dt><i>b</i></dt>
628 <dd>
629 data to be padded (bytes)
630 </dd>
631 </dl><dl>
632 <dt>Returns:</dt>
633 <dd>
634 padded data (bytes)
635 </dd>
636 </dl>
637 <div align="right"><a href="#top">Up</a></div>
638 <hr /><hr />
639 <a NAME="decryptData" ID="decryptData"></a>
640 <h2>decryptData</h2>
641 <b>decryptData</b>(<i>key, data, mode=AESModeOfOperation.ModeOfOperation["CBC"]</i>)
642 <p>
643 Module function to decrypt the given data with the given key.
644 </p><dl>
645 <dt><i>key</i></dt>
646 <dd>
647 key to be used for decryption (bytes)
648 </dd><dt><i>data</i></dt>
649 <dd>
650 data to be decrypted (with initialization vector prepended) (bytes)
651 </dd><dt><i>mode</i></dt>
652 <dd>
653 mode of operations (0, 1 or 2)
654 </dd>
655 </dl><dl>
656 <dt>Returns:</dt>
657 <dd>
658 decrypted data (bytes)
659 </dd>
660 </dl><dl>
661 <dt>Raises <b>ValueError</b>:</dt>
662 <dd>
663 key size is invalid or decrypted data is invalid
664 </dd>
665 </dl>
666 <div align="right"><a href="#top">Up</a></div>
667 <hr /><hr />
668 <a NAME="encryptData" ID="encryptData"></a>
669 <h2>encryptData</h2>
670 <b>encryptData</b>(<i>key, data, mode=AESModeOfOperation.ModeOfOperation["CBC"]</i>)
671 <p>
672 Module function to encrypt the given data with the given key.
673 </p><dl>
674 <dt><i>key</i></dt>
675 <dd>
676 key to be used for encryption (bytes)
677 </dd><dt><i>data</i></dt>
678 <dd>
679 data to be encrypted (bytes)
680 </dd><dt><i>mode</i></dt>
681 <dd>
682 mode of operations (0, 1 or 2)
683 </dd>
684 </dl><dl>
685 <dt>Returns:</dt>
686 <dd>
687 encrypted data prepended with the initialization vector (bytes)
688 </dd>
689 </dl>
690 <div align="right"><a href="#top">Up</a></div>
691 <hr /><hr />
692 <a NAME="strip_PKCS7_padding" ID="strip_PKCS7_padding"></a>
693 <h2>strip_PKCS7_padding</h2>
694 <b>strip_PKCS7_padding</b>(<i>b</i>)
695 <p>
696 Function to strip off PKCS7 padding.
697 </p><dl>
698 <dt><i>b</i></dt>
699 <dd>
700 data to be stripped (bytes)
701 </dd>
702 </dl><dl>
703 <dt>Returns:</dt>
704 <dd>
705 stripped data (bytes)
706 </dd>
707 </dl>
708 <div align="right"><a href="#top">Up</a></div>
709 <hr />
710 </body></html>

eric ide

mercurial