Guest User

Untitled

a guest
Jul 26th, 2018
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import cryptography.fernet
  2. import json
  3.  
  4.  
  5. def generate_auth_config(json_file_name, host, port, username, pwd):
  6. key = cryptography.fernet.Fernet.generate_key()
  7. f = cryptography.fernet.Fernet(key)
  8. token = f.encrypt(pwd.encode('ascii')) # unicode intp byte string
  9. config = dict(hostname=host, port=port, username=username, key=key.decode('ascii'),
  10. password_token=token.decode('ascii'))
  11.  
  12. json.dump(config, open(json_file_name, 'w'))
  13.  
  14.  
  15. generate_auth_config('ftpauth.json', 'localhost', 21, 'training', 'training')
  16.  
  17.  
  18.  
  19. """
  20. print('encrypt :', token)
  21.  
  22. password = f.decrypt(token)
  23. print(password)
  24. print(type(password))
  25. print(password.decode('ascii')) # byte into unicode
  26. """
Add Comment
Please, Sign In to add comment