diff options
author | clarkzjw <[email protected]> | 2023-02-23 15:38:38 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-23 15:38:38 -0800 |
commit | 20b8220a12fc92f95ecae267ce4eb5a80584f564 (patch) | |
tree | 1090256b48a76aae7afe2e10b860a02b43790807 /util.py | |
parent | 31a2d111d1c0ceb2ebfd5bb5daf4ee0ab2de4eb4 (diff) | |
parent | 4cee8500a51aff6d0a445a3a6259cafed92d4845 (diff) | |
download | swarm2fediverse-20b8220a12fc92f95ecae267ce4eb5a80584f564.tar.gz |
Merge branch 'feature/encryption'
- bot: encrypt access_key with cryptography.fernet library
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -0,0 +1,18 @@ | |||
1 | from cryptography.fernet import Fernet | ||
2 | |||
3 | |||
4 | def encrypt(input: str, key: str) -> str: | ||
5 | f = Fernet(key) | ||
6 | return f.encrypt(bytes(input, 'utf-8')).decode('utf-8') | ||
7 | |||
8 | |||
9 | def decrypt(input: str, key: str) -> str: | ||
10 | f = Fernet(key) | ||
11 | return f.decrypt(input).decode('utf-8') | ||
12 | |||
13 | |||
14 | # if __name__ == "__main__": | ||
15 | # key = Fernet.generate_key().decode('utf-8') | ||
16 | # print(key) | ||
17 | # print(encrypt("Hello World!", key)) | ||
18 | # print(decrypt(encrypt("Hello World!", key), key)) | ||