fastapi-dls/app/helper.py

21 lines
518 B
Python
Raw Normal View History

from Crypto.PublicKey import RSA
from Crypto.PublicKey.RSA import RsaKey
2022-12-16 15:51:14 +03:00
def load_file(filename) -> bytes:
with open(filename, 'rb') as file:
content = file.read()
return content
def load_key(filename) -> RsaKey:
return RSA.import_key(extern_key=load_file(filename), passphrase=None)
2022-12-16 15:51:14 +03:00
def private_bytes(rsa: RsaKey) -> bytes:
return rsa.export_key(format='PEM', passphrase=None, protection=None)
2022-12-16 15:51:14 +03:00
def public_key(rsa: RsaKey) -> bytes:
return rsa.public_key().export_key(format='PEM')