【问题标题】:How to get an encryption key from file如何从文件中获取加密密钥
【发布时间】:2022-01-15 13:09:40
【问题描述】:

我正在尝试从 Google Chrome 获取加密密钥,但收到一条错误消息:

line 13, in find_crypt
print(encrypt['encryption_key'])
KeyError: 'encryption_key'

代码是:

from genericpath import exists
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 + '\\Google\\Chrome\\User Data\\Default'
    }

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

if __name__ == '__main__':
    main()

【问题讨论】:

  • edit,并在注释中注明。

标签: python google-chrome dictionary encryption


【解决方案1】:

本地状态文件不存储任何名为 encryption_keykey,而是使用 加密密钥

这就是为什么您的 Python 程序 大喊 [在第 13 行] 它找不到任何名为 encryption_key 的密钥。

encrypted_key 也位于另一个名为 os_crypt

的对象中

废话不多说,下面是修改后的代码:)

def find_crypt(path):
    path = path.replace('\Default', '')
    print(path)
    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['os_crypt']['encrypted_key'])

【讨论】:

    猜你喜欢
    • 2020-02-29
    • 1970-01-01
    • 2017-10-02
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2012-05-02
    • 2018-11-29
    • 2021-07-26
    相关资源
    最近更新 更多