cubicweb/crypto.py
branch3.26
changeset 12615 7abe23cbfda1
parent 11767 432f87a63057
child 12616 bfab695b740a
equal deleted inserted replaced
12605:bd6ba326765e 12615:7abe23cbfda1
    34         return _CYPHERERS[seed]
    34         return _CYPHERERS[seed]
    35 
    35 
    36 
    36 
    37 def encrypt(data, seed):
    37 def encrypt(data, seed):
    38     string = pickle.dumps(data)
    38     string = pickle.dumps(data)
    39     string = string + '*' * (8 - len(string) % 8)
    39     string = string + b'*' * (8 - len(string) % 8)
    40     string = b64encode(_cypherer(seed).encrypt(string))
    40     string = b64encode(_cypherer(seed).encrypt(string))
    41     return unicode(string)
    41     return string.decode('utf-8')
    42 
    42 
    43 
    43 
    44 def decrypt(string, seed):
    44 def decrypt(string, seed):
       
    45     string = string.encode('utf-8')
    45     # pickle ignores trailing characters so we do not need to strip them off
    46     # pickle ignores trailing characters so we do not need to strip them off
    46     string = _cypherer(seed).decrypt(b64decode(string))
    47     string = _cypherer(seed).decrypt(b64decode(string))
    47     return pickle.loads(string)
    48     return pickle.loads(string)