I have an encrypted session key I need to decrypt using python and really have no idea how to go about that.
I've been provided with the passphrase, salt and hmac key. The string I need to decode is base64 encoded and when decoded it's a pipe delineated key and expiry date (session key + pipe delimiter + date time)
The session key is encrypted "using the AES-256-CBC cipher with a passcode built using PBKDF2 - Password-Based Key Derivation Function 2. The encrypted payload is then signed with an HMAC key."
How would I go about that using Python? What are the best libraries for this?
Below is one of my many attempts (edited based on @topaco's comment):
from base64 import b64decode
import hashlib
import pyaes
import os
PASSWORD = b"password provided"
SALT = b"Salt provided"
iv = os.urandom(16)
ciphertext = "message to decode"
passcode = hashlib.pbkdf2_hmac('sha256', PASSWORD, SALT, 1000)
aes = pyaes.AESModeOfOperationCBC(passcode, iv=iv)
encrypter = pyaes.Encrypter(pyaes.AESModeOfOperationCBC(passcode, iv))
decrypter = encrypter.feed(ciphertext)
decrypter += encrypter.feed()
decrypter.feed()if the ciphertext is longer than 1 block (16 bytes), here and here. For other Python Crypto libraries, see e.g. here. - Topaco