-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #989 from Amruta101998/master
added cryptography program in python folder
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
Program's_Contributed_By_Contributors/Python_Programs/Cryptography.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from cryptography.fernet import Fernet | ||
|
||
def genratePassKey(): | ||
key = Fernet.generate_key() | ||
print(key) | ||
print(type(key)) | ||
abc = open("PasswordKey.key",'wb') | ||
abc.write(key) | ||
abc.close() | ||
|
||
def getMyKey(): | ||
abc = open("PasswordKey.key",'rb') | ||
return abc.read() | ||
|
||
def encryptMessage(message_normal): | ||
key = getMyKey() | ||
k = Fernet(key) | ||
encrypted_Message = k.encrypt(message_normal) | ||
return encrypted_Message | ||
|
||
def decryptMessage(message_secret): | ||
key = getMyKey() | ||
k = Fernet(key) | ||
decrypted_Message = k.decrypt(message_secret) | ||
return decrypted_Message | ||
|
||
encryptMessage(b" HEY PYTHON LEARNER") | ||
|
||
decryptMessage(b'gAAAAABhbBReu34y2Z5wPDu_2GHtdtSdXl3iLvwYtOk8F5pIc9HToKfJmGLWXbCYiwhWTFE77_f3J_S0_plkssSoSOzS6pdOEfEWoOSTg7BNao5S_49NgJc=') |