def testchacha(): sk, pk = rsa.generate_key() key = "12345678" x = chacha20.encrypt(key,sk) start = time.time() for i in range(1000000): chacha20.decrypt(key,x) end = time.time() print(end - start)
def generate_check_pass_file(username, password): with open(password_check_path, 'w+') as fi: new_check_data = '%s:%s:%s' % (''.join( random.sample(string.ascii_letters + string.digits, random.randint(16, 32))), username, ''.join( random.sample( string.ascii_letters + string.digits, random.randint(16, 32)))) enc_check_data = chacha20.encrypt(password, new_check_data) fi.write( str(base64.b64encode(enc_check_data), encoding=config.encoding)) return True
def generate_key(password, force=False): # Check if key exist if not os.path.exists(root_dir): os.makedirs(root_dir) # Create if not os.path.exists(private_key_path) or force: print('Generating key pairs...') sk, pk = rsa.generate_key() with open(private_key_path, 'w') as fi: b64_res = base64.b64encode(chacha20.encrypt(password, sk)) fi.write(str(b64_res, encoding=config.encoding)) with open(public_key_path, 'w') as fi: fi.write(str(pk, encoding=config.encoding)) else: raise Exception('Key pair exist') return True