getting a specific key from file

  dictionary, encryption, google-chrome, python

I’m trying to get the encryption key of google chrome and I get an error everytime saying:
line 13, in find_crypt
print(encrypt[‘encryption_key’])
KeyError: ‘encryption_key’

import win32crypt
import json
import os

def find_crypt(path):
    path = path.replace('Default', '')
    
    for file in os.listdir(path):
        if file == 'Local State':
            f = open('{0}{1}'.format(path, file), 'r', encoding='utf-8')
            encrypt = json.load(f)
            print(encrypt['encryption_key'])

def find_passwords(path):
    for file in os.listdir(path):
        if file == 'Login Data':
                pass

def main():
    local = os.getenv('LocalAppData')
    roaming = os.getenv('AppData')

    directories = {
        'chrome' : local + 'GoogleChromeUser DataDefault'
    }

    for name, directory in directories.items():
        if not os.path.exists(directory):
            continue
        else:
            find_crypt(directory)
            find_passwords(directory)

if __name__ == '__main__':
    main()

Source: Python Questions

LEAVE A COMMENT