equal
deleted
inserted
replaced
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """Simple cryptographic routines, based on python-crypto.""" |
18 """Simple cryptographic routines, based on python-crypto.""" |
19 |
19 |
20 |
20 |
21 from base64 import b64encode, b64decode |
21 from base64 import b64encode, b64decode |
22 |
22 import pickle |
23 from six.moves import cPickle as pickle |
|
24 |
23 |
25 from Crypto.Cipher import Blowfish |
24 from Crypto.Cipher import Blowfish |
26 |
25 |
27 |
26 |
28 _CYPHERERS = {} |
27 _CYPHERERS = {} |
36 |
35 |
37 def encrypt(data, seed): |
36 def encrypt(data, seed): |
38 string = pickle.dumps(data) |
37 string = pickle.dumps(data) |
39 string = string + '*' * (8 - len(string) % 8) |
38 string = string + '*' * (8 - len(string) % 8) |
40 string = b64encode(_cypherer(seed).encrypt(string)) |
39 string = b64encode(_cypherer(seed).encrypt(string)) |
41 return unicode(string) |
40 return str(string) |
42 |
41 |
43 |
42 |
44 def decrypt(string, seed): |
43 def decrypt(string, seed): |
45 # pickle ignores trailing characters so we do not need to strip them off |
44 # pickle ignores trailing characters so we do not need to strip them off |
46 string = _cypherer(seed).decrypt(b64decode(string)) |
45 string = _cypherer(seed).decrypt(b64decode(string)) |