def encrypt(pubkeypath, filepath): pubkey = crypto.open_keypair(pubkeypath) content = readFile(filepath) crypto = crypto.encrypt(pubkey, content) writeFile(filepath + ".secret", crypto, True)
def decrypt(prvkeypath, filepath): try: prvkey = crypto.open_keypair(prvkeypath) content = readFile(filepath, True) plain = crypto.decrypt(prvkey, content).decode() writeFile(filepath + ".plain", plain) except ValueError: print("Could not decrypt [" + filepath + "]")
def open_keypair(keypath): keystr = readFile(keypath, True) try: keys = RSA.importKey(keystr) except ValueError: print("Enter password for the private key") pw = input(' >> ') try: keys = RSA.importKey(keystr, pw) except ValueError: print("...Wrong password") raise ValueError("Wrong Password") return keys
def sdecrypt(passphrase, filepath): ciphertext = readFile(filepath, bytestring=True) plaintext = crypto.sdecrypt(passphrase, ciphertext) print(plaintext) writeFile(filepath + ".unlocked", plaintext)
def sencrypt(passphrase, filepath): plaintext = readFile(filepath) ciphertext = crypto.sencrypt(passphrase, plaintext) print(ciphertext) writeFile(filepath + ".locked", ciphertext, bytestring=True)