File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ from cryptography .fernet import Fernet
2
+ import os
3
+
4
+ key1 = input ("enter the encyption key" )
5
+ with open ('new.json' ,'rb' ) as f :
6
+ data = f .read ()
7
+ q = Fernet (key1 )
8
+ decrypted_message = q .decrypt (data )
9
+
10
+ with open ('decrypted.json' ,'wb' ) as f :
11
+ f .write (decrypted_message )
Original file line number Diff line number Diff line change
1
+ from cryptography .fernet import Fernet
2
+ import os
3
+
4
+
5
+ #taking key as user input
6
+ key1 = input ("enter the encyption key" )
7
+
8
+ with open ('test_data/apikeys2.json' ,'rb' ) as f :
9
+ data = f .read ()
10
+
11
+ #encrypting the data from the given file name
12
+
13
+ fernet = Fernet (key1 )
14
+ encrypted = fernet .encrypt (data )
15
+ os .remove ('test_data/apikeys2.json' ) #deleting the file with the original api key
16
+
17
+ with open ('new.json' ,'wb' ) as f :
18
+ f .write (encrypted )
19
+
20
+
Original file line number Diff line number Diff line change
1
+ from cryptography .fernet import Fernet
2
+ import os
3
+ #generating the key and storing them in a file
4
+ key = Fernet .generate_key ()
5
+ #creating the key file in which the key'll be stored
6
+ file = open ('key.key' ,'wb' )
7
+ file .write (key )
8
+ file .close ()
You can’t perform that action at this time.
0 commit comments