Problems with hex
#1
Sad 
Hello, I am writing my own module and its flow is roughly as follows: the password goes through Argon2id, then it is converted to HEX. After HEX, it is processed as ASCII, and only after that the password is passed to AES-GCM. I have a problem precisely at the stage of converting to HEX and processing as ASCII. As a basis, I used module 34000. Here is an example implementation in Python:
Code:
import base64 import argon2 from Crypto.Cipher import AES password = b"hashcat!123" salt = base64.b64decode("NjE3YjNlMTJjNTA5YmUxNTAyMDNjNTllMzY4NjcwNDAwOTE4ODgzZmFhMmY5Mjg0OGVmYzAyYmY5OWVmYzZkYg==") b64_blob = "ue6Dewmd1Yx7N9vbWSsCwrY9aUO9ntpgYJxRngk0nlYJsUQSHtUczSKk3GXoGzH1niJAmVKE4y3IY6DXq5JIvHEPlPMk1hw87fActLNxY4lBNxxaAjlACfmMrj6Jp6o6S24KcIEMYKtZf88o51NzJkRytTMkDkJ9hie8fanwZ3IOpEE8pwTq78vci/foXxY=" decoded_blob = base64.b64decode(b64_blob) print("--- Argon 2id hashing ---") ph = argon2.low_level.hash_secret_raw( password, salt, time_cost=3, memory_cost=64*1024, parallelism=4, hash_len=16, type=argon2.low_level.Type.ID ) print(f"Raw key (16 bytes): {ph.hex()}") print("-" * 30) print("--- Step 2: HEX conversion of the key ---") hex_key = ph.hex().encode('ascii') print(f"Final AES key (32 bytes): {hex_key.decode('ascii')}") print("-" * 30) print("--- Step 3: AES-GCM decryption ---") IV_SIZE = 16 TAG_SIZE = 16 iv = decoded_blob[:IV_SIZE] ciphertext = decoded_blob[IV_SIZE:-TAG_SIZE] tag = decoded_blob[-TAG_SIZE:] print(f"IV: {iv.hex()}") print(f"Ciphertext: {ciphertext.hex()}") print(f"Auth Tag: {tag.hex()}") try: cipher = AES.new(hex_key, AES.MODE_GCM, nonce=iv) decrypted_data = cipher.decrypt_and_verify(ciphertext, tag) result = decrypted_data.decode('utf-8') print("\n[SUCCESS] Decryption and tag verification succeeded!") print(f"Decrypted data: '{result}'") except (ValueError, KeyError) as e: print(f"\n[FAILURE] Decryption or tag verification error: {e}")
Reply


Messages In This Thread
Problems with hex - by mandatory - 08-24-2025, 02:13 PM
RE: Problems with hex - by buka - 08-24-2025, 02:20 PM
RE: Problems with hex - by mandatory - 08-24-2025, 02:23 PM
RE: Problems with hex - by mandatory - 08-24-2025, 02:25 PM
RE: Problems with hex - by atom - 08-28-2025, 03:45 PM
RE: Problems with hex - by mandatory - 08-29-2025, 10:29 PM
RE: Problems with hex - by mandatory - 08-30-2025, 02:45 AM