Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cryptography.fernet
- import json
- def generate_auth_config(json_file_name, host, port, username, pwd):
- key = cryptography.fernet.Fernet.generate_key()
- f = cryptography.fernet.Fernet(key)
- token = f.encrypt(pwd.encode('ascii')) # unicode intp byte string
- config = dict(hostname=host, port=port, username=username, key=key.decode('ascii'),
- password_token=token.decode('ascii'))
- json.dump(config, open(json_file_name, 'w'))
- generate_auth_config('ftpauth.json', 'localhost', 21, 'training', 'training')
- """
- print('encrypt :', token)
- password = f.decrypt(token)
- print(password)
- print(type(password))
- print(password.decode('ascii')) # byte into unicode
- """
Add Comment
Please, Sign In to add comment