connpy/conn/tools.py
2022-03-17 19:05:23 -03:00

26 lines
516 B
Python
Executable File

#!/usr/bin/python3
#Imports
import os
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
import ast
#Constants
#Variables
#functions and clsses
def encrypt(password, keyfile=None):
if keyfile is None:
home = os.path.expanduser("~")
keyfile = home + '/.config/conn/.osk'
key = RSA.import_key(open(keyfile).read())
publickey = key.publickey()
encryptor = PKCS1_OAEP.new(publickey)
password = encryptor.encrypt(password.encode("utf-8"))
return password