-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret.py
52 lines (43 loc) · 1.39 KB
/
secret.py
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
from cryptography.fernet import Fernet
import json
from getpass import getpass
import os
# Generate a key for encryption and decryption
# You must keep this key safe. Anyone with this key can decrypt your data.
key = Fernet.generate_key()
cipher_suite = Fernet(key)
# Function to encrypt data
def encrypt_data(data):
return cipher_suite.encrypt(data.encode())
# Function to decrypt data
def decrypt_data(encrypted_data):
return cipher_suite.decrypt(encrypted_data).decode()
# Store usernames and passwords
credentials = {
"user2": encrypt_data("password2")
}
# Save credentials to a file
with open('credentials.json', 'w') as file:
json.dump({user: cred.decode() for user, cred in credentials.items()}, file)
# Load credentials from a file
with open('credentials.json', 'r') as file:
loaded_credentials = json.load(file)
loaded_credentials = {user: decrypt_data(cred.encode()) for user, cred in loaded_credentials.items()}
OMERO_USER="michaelm"
OMERO_PASSWORD=
OMERO_HOST="ctomero01lp.jax.org"
OMERO_PORT=4064
if __name__ == "__main__":
print("Enter your username")
username = input()
print(username)
print("Enter your password")
password = getpass()
print(encrypt_data(password))
print(loaded_credentials)
print(loaded_credentials[OMERO_USER])
print(OMERO_PASSWORD)
print(OMERO_USER)
print(OMERO_HOST)
print(OMERO_PORT)
print(key)