0

我使用了如下密码库:

    from cryptography.fernet import Fernet

    # key generation
    key = Fernet.generate_key()
    
    # string the key in a file
    with open('filekey.key', 'wb') as filekey:
        filekey.write(key)
    
    # opening the key
    with open('filekey.key', 'rb') as filekey:
        key = filekey.read()
    
    # using the generated key
    fernet = Fernet(key)
    
    # opening the original file to encrypt
    with open('test.py', 'rb') as file:
        original = file.read()
        
    # encrypting the file
    encrypted = fernet.encrypt(original)
    
    # opening the file in write mode and
    # writing the encrypted data
    with open('test.py', 'wb') as encrypted_file:
        encrypted_file.write(encrypted)

然后生成名为 filekey.key 的文件,如下图所示,它包含加密密钥: 在此处输入图像描述

最后,当我运行服务器时,它显示 NotFound 错误,因为我加密的模块不存在,如下所示:

FileNotFoundError: [Errno 2] No such file or directory: 'test.py' - - -
4

0 回答 0