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 get_rsa_key(key_type, password=''): if key_type == 'pk': res = ''.join(open(public_key_path, 'r').readlines()) elif key_type == 'sk': enc_key = base64.b64decode(''.join( open(private_key_path, 'r').readlines())) res = str(chacha20.decrypt(password, enc_key), encoding=config.encoding) else: return False return res
def decrypt(cls, private_key, enc_session_key, ciphertext, tag=None): # Convert to bytes private_key = trans_to_bytes(private_key) enc_session_key = trans_to_bytes(enc_session_key) ciphertext = trans_to_bytes(ciphertext) # Load key and decrypt session key private_key_instance = RSA.import_key(private_key) cipher_rsa = PKCS1_OAEP.new(private_key_instance) session_key = cipher_rsa.decrypt(enc_session_key) # Decrypt ciphertext verify = False if tag is None: plain = chacha20.decrypt(session_key, ciphertext) else: plain, verify = chacha20.decrypt_and_verify(session_key, ciphertext, tag) return plain, verify
def attackSK(): name = userdata_service.load_unencrypted_data('name') with open(password_check_path, 'r+') as fi: check_data = base64.b64decode( bytes(''.join(fi.readlines()), encoding=config.encoding)) start = time.time() for pwd in get_pwd(strKey, 6): try: plaintext = str(chacha20.decrypt(pwd, check_data), encoding=config.encoding) except: continue if name in plaintext: print(pwd + "----------------------------------------------------------") break end = time.time() print(end - start)
def check_pass(password): if not check_user_data_integrity(): raise Exception('No password auth file') username = load_unencrypted_data('name') with open(password_check_path, 'r+') as fi: try: check_data = base64.b64decode( bytes(''.join(fi.readlines()), encoding=config.encoding)) plaintext = str(chacha20.decrypt(password, check_data), encoding=config.encoding) if username in plaintext: fi.close() generate_check_pass_file(username, password) return True except: return False return False