eric6/Utilities/crypto/__init__.py

changeset 7259
7c017076c12e
parent 7229
53054eb5b15a
child 7360
9190402e4505
equal deleted inserted replaced
7258:aff39db4dacc 7259:7c017076c12e
36 Module function to encode a password. 36 Module function to encode a password.
37 37
38 @param pw password to encode (string) 38 @param pw password to encode (string)
39 @return encoded password (string) 39 @return encoded password (string)
40 """ 40 """
41 pop = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" \ 41 pop = (
42 ".,;:-_!$?*+#" 42 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
43 rpw = "".join(random.sample(pop, 32)) + pw + \ 43 ".,;:-_!$?*+#"
44 )
45 rpw = (
46 "".join(random.sample(pop, 32)) +
47 pw +
44 "".join(random.sample(pop, 32)) 48 "".join(random.sample(pop, 32))
49 )
45 return EncodeMarker + base64.b64encode(rpw.encode("utf-8")).decode("ascii") 50 return EncodeMarker + base64.b64encode(rpw.encode("utf-8")).decode("ascii")
46 51
47 52
48 def pwDecode(epw): 53 def pwDecode(epw):
49 """ 54 """
270 success (boolean) 275 success (boolean)
271 """ 276 """
272 from .py3AES import encryptData 277 from .py3AES import encryptData
273 from .py3PBKDF2 import hashPasswordTuple 278 from .py3PBKDF2 import hashPasswordTuple
274 279
275 digestname, iterations, salt, pwHash = \ 280 digestname, iterations, salt, pwHash = hashPasswordTuple(
276 hashPasswordTuple(password, iterations=hashIterations) 281 password, iterations=hashIterations)
277 key = pwHash[:keyLength] 282 key = pwHash[:keyLength]
278 try: 283 try:
279 cipher = encryptData(key, data) 284 cipher = encryptData(key, data)
280 except ValueError: 285 except ValueError:
281 return b"", False 286 return b"", False

eric ide

mercurial