connpy/conn/tools.py

22 lines
497 B
Python
Raw Normal View History

2022-03-19 20:41:35 -03:00
#!/usr/bin/env python3
2022-03-17 19:05:23 -03:00
#Imports
import os
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
import ast
2022-03-19 20:41:35 -03:00
#functions and classes
2022-03-17 19:05:23 -03:00
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