def encrypt(passW): ''' encrypt the sqlite database ''' #double check the password checkPass = inp.secure_passphrase('Please enter your database password') if checkPass != passW.password: print('Your passwords don\'t match') passW.getPass(True) print('Encrypting database. Please wait...') bs = 128 inFile = 'igloo.dat' outFile = 'iceblock' if not os.path.isfile(inFile) and os.path.isfile(outFile): print('Database is already encrypted') return salt = str(rand.clockrnd())[:(bs - len('Salted__'))] in_file = open('igloo.dat', 'rb') out_file = open('iceblock', 'wb') key, iv = derive_key_and_iv(passW.password, salt, 32, bs) out_file.write('Salted__' + salt) finished = False while not finished: chunk = in_file.read(1024 * bs) if len(chunk) == 0 or len(chunk) % bs != 0: padding_length = (bs - len(chunk) % bs) or bs chunk += padding_length * chr(padding_length) finished = True out_file.write(aes.encryptData(key, chunk)) in_file.close() out_file.close() os.remove(inFile) return
def keyboardEntropy(keynum=64): """ 512 bit random number from keyboard and keypress timer """ keypress = get._Getch() typed = kr = 'Press some keys to generate a secure address...' hashes = rand.clockrnd() print(kr) for step in range(keynum, 0, -1): for cnt in xrange(10000000): # only loops on OSX hashes ^= rand.clockrnd() kr = keypress() get.flushKeybuffer(keypress) if kr != '': break typed += kr hashes ^= rand.clockrnd() out.prnt('\b\b\b\b\b\b{0:4d}\b\b\b\b\b'.format(step-1)) get.flushKeybuffer(keypress) out.prnt('\b\b\b\b\b\b{0:4s}\b\b\b\b\b\n'.format(' OK')) get.flushKeybuffer(keypress) return hashes ^ int(hashlib.sha512(typed*8).hexdigest(), 16)