Bonjour,
J'utilise l'API pycrypto pour faire du chiffrement AES, mais en simulant mon code ca me marque cela est-ce un beug ou un problème de codage, merci
Voila la console
Et voila le code en question :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Total time ciphered XOR in seconds: 7.8e-05 Total time deciphered XOR in seconds: 0.000116 Traceback (most recent call last): File "add_many_logentries.py", line 66, in <module> encrypted = cipher.encrypt('Secret Message A') File "add_many_logentries.py", line 28, in encrypt iv = Random.new().read( AES.block_size ) File "/usr/local/lib/python2.7/dist-packages/Crypto/Random/__init__.py", line 33, in new return _UserFriendlyRNG.new(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 221, in new return RNGFile(_get_singleton()) File "/usr/local/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 215, in _get_singleton _singleton = _LockingUserFriendlyRNG() File "/usr/local/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 159, in __init__ _UserFriendlyRNG.__init__(self) File "/usr/local/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 85, in __init__ self._fa = FortunaAccumulator.FortunaAccumulator() File "/usr/local/lib/python2.7/dist-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 119, in __init__ self.generator = FortunaGenerator.AESGenerator() File "/usr/local/lib/python2.7/dist-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 66, in __init__ self.counter = Counter.new(nbits=self.block_size*8, initial_value=0, little_endian=True) File "/usr/local/lib/python2.7/dist-packages/Crypto/Util/Counter.py", line 112, in new return _counter._newLE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut) TypeError: function takes at most 4 arguments (5 given)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Scripts to insert several data entries """ import urllib2, time import entry import hashlib import base64 from Crypto import Random from Crypto.Cipher import AES BS = 16 pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) unpad = lambda s : s[0:-ord(s[-1])] class AESCipher: def __init__( self, key ): self.key = key def encrypt( self, raw ): raw = pad(raw) iv = Random.new().read( AES.block_size ) cipher = AES.new( self.key, AES.MODE_CBC, iv ) return base64.b64encode( iv + cipher.encrypt( raw ) ) def decrypt( self, enc ): enc = base64.b64decode(enc) iv = enc[:16] cipher = AES.new(self.key, AES.MODE_CBC, iv ) return unpad(cipher.decrypt( enc[16:] )) from Crypto.Hash import * base_url = 'http://127.0.0.1:8080/' #base_url = 'http://alliantech3.appspot.com/' try: urllib2.urlopen(base_url+'auth/install') except urllib2.HTTPError: print "Already installed" for i in range(1): t1 = time.clock() cyphered_data1 = entry.xor_crypt_string("d0efc09c8ddbc06c8cbbd25e", encode=True) # cyphered_data2 = entry.xor_crypt_string("c06c8cbbd34f", encode=True) #cyphered_data3 = entry.xor_crypt_string("d34f", encode=True) #response = urllib2.urlopen(base_url+'data/add?device=FE78&time=%d&data=%s&duplicate=false&signal=30.5&station=here' % (time.time() - 1e2*i, cyphered_data1)) t2 = time.clock() - t1 print 'Total time ciphered XOR in seconds:', t2 t3 = time.clock() decyphered_data1=entry.xor_crypt_string(entry.xor_crypt_string(cyphered_data1, encode=True), decode=True) t4= time.clock() -t3 print 'Total time deciphered XOR in seconds:', t4 #######Algorithme AES 128 bits ##############" cipher = AESCipher('mysecretpassword') encrypted = cipher.encrypt('Secret Message A') #decrypted = cipher.decrypt(encrypted) print encrypted # print decrypted print cipher
Partager