58 |
58 |
59 def __getMasterPassword(): |
59 def __getMasterPassword(): |
60 """ |
60 """ |
61 Private module function to get the password from the user. |
61 Private module function to get the password from the user. |
62 """ |
62 """ |
|
63 from .py3PBKDF2 import verifyPassword |
|
64 |
63 global MasterPassword |
65 global MasterPassword |
64 |
66 |
65 pw, ok = QInputDialog.getText( |
67 pw, ok = QInputDialog.getText( |
66 None, |
68 None, |
67 QCoreApplication.translate("Crypto", "Master Password"), |
69 QCoreApplication.translate("Crypto", "Master Password"), |
68 QCoreApplication.translate("Crypto", "Enter the master password:"), |
70 QCoreApplication.translate("Crypto", "Enter the master password:"), |
69 QLineEdit.EchoMode.Password, |
71 QLineEdit.EchoMode.Password, |
70 ) |
72 ) |
71 if ok: |
73 if ok: |
72 from .py3PBKDF2 import verifyPassword |
|
73 |
|
74 masterPassword = Preferences.getUser("MasterPassword") |
74 masterPassword = Preferences.getUser("MasterPassword") |
75 try: |
75 try: |
76 if masterPassword: |
76 if masterPassword: |
77 if verifyPassword(pw, masterPassword): |
77 if verifyPassword(pw, masterPassword): |
78 MasterPassword = pwEncode(pw) |
78 MasterPassword = pwEncode(pw) |
111 @param pw password to encrypt (string) |
111 @param pw password to encrypt (string) |
112 @param masterPW password to be used for encryption (string) |
112 @param masterPW password to be used for encryption (string) |
113 @return encrypted password (string) and flag indicating |
113 @return encrypted password (string) and flag indicating |
114 success (boolean) |
114 success (boolean) |
115 """ |
115 """ |
|
116 from .py3AES import encryptData |
|
117 from .py3PBKDF2 import hashPasswordTuple |
|
118 |
116 if masterPW is None: |
119 if masterPW is None: |
117 if MasterPassword is None: |
120 if MasterPassword is None: |
118 __getMasterPassword() |
121 __getMasterPassword() |
119 if MasterPassword is None: |
122 if MasterPassword is None: |
120 return "", False |
123 return "", False |
121 |
124 |
122 masterPW = pwDecode(MasterPassword) |
125 masterPW = pwDecode(MasterPassword) |
123 |
126 |
124 from .py3PBKDF2 import hashPasswordTuple |
|
125 |
|
126 digestname, iterations, salt, pwHash = hashPasswordTuple(masterPW) |
127 digestname, iterations, salt, pwHash = hashPasswordTuple(masterPW) |
127 key = pwHash[:32] |
128 key = pwHash[:32] |
128 from .py3AES import encryptData |
|
129 |
|
130 try: |
129 try: |
131 cipher = encryptData(key, pw.encode("utf-8")) |
130 cipher = encryptData(key, pw.encode("utf-8")) |
132 except ValueError: |
131 except ValueError: |
133 return "", False |
132 return "", False |
134 return ( |
133 return ( |
152 @param epw hashed password to decrypt (string) |
151 @param epw hashed password to decrypt (string) |
153 @param masterPW password to be used for decryption (string) |
152 @param masterPW password to be used for decryption (string) |
154 @return decrypted password (string) and flag indicating |
153 @return decrypted password (string) and flag indicating |
155 success (boolean) |
154 success (boolean) |
156 """ |
155 """ |
|
156 from .py3AES import decryptData |
|
157 from .py3PBKDF2 import rehashPassword |
|
158 |
157 if not epw.startswith(CryptoMarker): |
159 if not epw.startswith(CryptoMarker): |
158 return epw, False # it was not encoded using pwEncrypt |
160 return epw, False # it was not encoded using pwEncrypt |
159 |
161 |
160 if masterPW is None: |
162 if masterPW is None: |
161 if MasterPassword is None: |
163 if MasterPassword is None: |
162 __getMasterPassword() |
164 __getMasterPassword() |
163 if MasterPassword is None: |
165 if MasterPassword is None: |
164 return "", False |
166 return "", False |
165 |
167 |
166 masterPW = pwDecode(MasterPassword) |
168 masterPW = pwDecode(MasterPassword) |
167 |
|
168 from .py3AES import decryptData |
|
169 from .py3PBKDF2 import rehashPassword |
|
170 |
169 |
171 hashParameters, epw = epw[3:].rsplit(Delimiter, 1) |
170 hashParameters, epw = epw[3:].rsplit(Delimiter, 1) |
172 try: |
171 try: |
173 # recreate the key used to encrypt |
172 # recreate the key used to encrypt |
174 key = rehashPassword(masterPW, hashParameters)[:32] |
173 key = rehashPassword(masterPW, hashParameters)[:32] |
310 @param keyLength length of the key to be generated for decryption |
309 @param keyLength length of the key to be generated for decryption |
311 (16, 24 or 32) |
310 (16, 24 or 32) |
312 @return decrypted data (bytes) and flag indicating |
311 @return decrypted data (bytes) and flag indicating |
313 success (boolean) |
312 success (boolean) |
314 """ |
313 """ |
|
314 from .py3AES import decryptData |
|
315 from .py3PBKDF2 import rehashPassword |
|
316 |
315 if not edata.startswith(CryptoMarker.encode("utf-8")): |
317 if not edata.startswith(CryptoMarker.encode("utf-8")): |
316 return edata, False # it was not encoded using dataEncrypt |
318 return edata, False # it was not encoded using dataEncrypt |
317 |
|
318 from .py3AES import decryptData |
|
319 from .py3PBKDF2 import rehashPassword |
|
320 |
319 |
321 hashParametersBytes, edata = edata[3:].rsplit(Delimiter.encode("utf-8"), 1) |
320 hashParametersBytes, edata = edata[3:].rsplit(Delimiter.encode("utf-8"), 1) |
322 hashParameters = hashParametersBytes.decode() |
321 hashParameters = hashParametersBytes.decode() |
323 try: |
322 try: |
324 # recreate the key used to encrypt |
323 # recreate the key used to encrypt |