-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateCredentials.py
More file actions
54 lines (43 loc) · 1.09 KB
/
createCredentials.py
File metadata and controls
54 lines (43 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 17 08:19:38 2019
@author: BEHAT
"""
from cryptography.fernet import Fernet
import getpass
from lxml import etree
keyfile='mrclean.key'
xmlfile='mrclean.xml'
uname = input("Username: ")
password = getpass.getpass()
key = Fernet.generate_key()
k1 = key.decode('ASCII')
f = open(keyfile,'w')
f.write(key.decode('ASCII'))
f.close()
f = Fernet(key)
token = f.encrypt(password.encode('ASCII'))
user = f.encrypt(uname.encode('ASCII'))
root = etree.Element("data")
etree.SubElement(root,"username").text=uname
etree.SubElement(root,"user").text=user
etree.SubElement(root,"password").text=token
xmloutput = etree.tostring(root, pretty_print=True)
f = open(xmlfile,'w')
f.write(xmloutput.decode('ASCII'))
f.close()
"""
# Read the data again
f = open(keyfile, 'r')
k2=f.readline()
f.close()
key2=k2.encode('ASCII')
tree = etree.parse(xmlfile)
u2=(tree.find("user")).text
p2=(tree.find("password")).text
f = Fernet(key2)
u3 = f.decrypt(u2.encode('ASCII')).decode('ASCII')
p3 = f.decrypt(p2.encode('ASCII')).decode('ASCII')
print("User: ",u3)
print("Password: ",p3)
"""