Search code examples
python-3.xwinapi

Python3 CryptUnprotectData() TypeError expected an object with a buffer interface


I was browsing over the net for some information about CryptUnprotectData and WZC. I found this small script that is used for decrypting stored Wireless passwords on Vista. I tried with Python3 (it was written probably for Python 2.X) but it gives me: TypeError expected an object with a buffer interface. I'm not quite sure how to fix it. It is simple script:

    import win32crypt
    mykey = "Insert keyMaterial"
    binout = []
    for i in range(len(mykey)):
        if i % 2 == 0:
            binout.append(chr(int(mykey[i:i+2],16)))
    pwdHash=''.join(binout)

    output = win32crypt.CryptUnprotectData(pwdHash,None,None,None,0)

    print ("hex:", "".join(["%02X" % ord(char) for char in output[1]]))

    print ("ascii:", output[1])

Script is from here


Solution

  • You are giving it string/unicode data when it expected binary/bytes data.

    If it is written for Python 2 it is unlikely to work on Python 3 without some modifications. Use Python 2 (or fix it).