Last active
November 16, 2023 17:12
-
-
Save ameyanekar/8d2fe3f2d611f153d14dcc291eca6c60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from Crypto.Cipher import AES | |
from Crypto.Util.Padding import unpad | |
import base64 | |
if not len(sys.argv) > 1: | |
print("Pass ciphertext to decrypt on the command line:") | |
print("Usage: python vfs-decrypt.py EncryptedId") | |
sys.exit() | |
encrypted_data = sys.argv[1] | |
#Add the key and IV from the report here | |
def aes_decrypt(hex_key, hex_iv, encrypted_data): | |
# Convert hex key and IV to bytes | |
key = bytes.fromhex(hex_key) | |
iv = bytes.fromhex(hex_iv) | |
# Ensure the key and IV are 16 bytes for AES-128 | |
if len(key) != 16 or len(iv) != 16: | |
raise ValueError("Key and IV must be 16 bytes (32 hex characters) long.") | |
# Decode the encrypted data from base64 | |
encrypted_data_bytes = base64.b64decode(encrypted_data) | |
# Initializing the cipher with the given IV for decryption | |
cipher = AES.new(key, AES.MODE_CBC, iv) | |
# Decrypting the data | |
decrypted_data = unpad(cipher.decrypt(encrypted_data_bytes), AES.block_size) | |
# Converting decrypted data to string | |
return decrypted_data.decode('utf-8') | |
decrypted_data = aes_decrypt(hex_key, hex_iv, encrypted_data) | |
print("Decrypted:", decrypted_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment