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

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

eric ide

mercurial