This script was created with the idea that you would like to casually encrypt the password on the server, decrypt it, and use it.
#How to keep the password etc. encrypted on the server
#Save it with a common key and call it with jupyter.
#I wonder if it's okay for casual use
import gnupg
gpg = gnupg.GPG()
#Create text to save
conf = """
{'id':'foo',
'passwor':'bar'
}
"""
#Now text-encrypt with symmetric key bar
x = gpg.encrypt(conf, symmetric=True, passphrase='bar', encrypt=False)
#File test.Saved in txt Binary, utf-Make 8 texts.
f = open('test.txt','w')
f.write(x.data.decode('utf-8'))
f.close()
#Recall the saved file and decrypt it.
f = open('test.txt','r')
y = gpg.decrypt((f.read()), passphrase='bar')
conf = eval(y.data.decode('utf-8'))
print(conf)
Recommended Posts