0

I used cryptography library like as following:

    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)

Then file called filekey.key generated like as image below it contains the encryption key: enter image description here

Finally when I run the server it show NotFound error because the module what I encrypted doesn't exist like below:

FileNotFoundError: [Errno 2] No such file or directory: 'test.py' - - -
  • 1
    In the directory you're running this from, does `test.py` exist? I don't believe this is a problem with your use of `cryptography` but the way you're running your script; python just can't find `test.py` at the given path – JJ Hassan Feb 09 '22 at 11:38
  • This file is implementing how i use the library while the encryption , the file `test.py` doesn't exist, but if i decrypt the file the server will run normally. The problem in Odoo server – Ahmed Emad Feb 09 '22 at 12:37

0 Answers0