2022-12-19 14:58:48 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-12-19 14:58:48 +03:00
|
|
|
def load_key(filename) -> RsaKey:
|
|
|
|
return RSA.import_key(extern_key=load_file(filename), passphrase=None)
|
2022-12-16 15:51:14 +03:00
|
|
|
|
|
|
|
|
2022-12-19 14:58:48 +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
|
|
|
|
|
|
|
|
2022-12-19 14:58:48 +03:00
|
|
|
def public_key(rsa: RsaKey) -> bytes:
|
|
|
|
return rsa.public_key().export_key(format='PEM')
|