from cryptography.fernet import Fernet # Generate a key and instantiate a Fernet instance key = Fernet.generate_key() cipher_suite = Fernet(key) # Save the key to a file (keep this file secure) with open('secret.key', 'wb') as key_file: key_file.write(key) # Encrypt the credentials #insert password and token inside the commas username = '' password = '' security_token = '' encrypted_username = cipher_suite.encrypt(username.encode()) encrypted_password = cipher_suite.encrypt(password.encode()) encrypted_security_token = cipher_suite.encrypt(security_token.encode()) # Save the encrypted credentials to a file with open('encrypted_credentials.txt', 'wb') as enc_file: enc_file.write(encrypted_username + b'\n') enc_file.write(encrypted_password + b'\n') enc_file.write(encrypted_security_token + b'\n') print("Credentials encrypted and saved to file.")