2022-12-28 13:53:56 +03:00
|
|
|
def load_file(filename) -> bytes:
|
|
|
|
with open(filename, 'rb') as file:
|
|
|
|
content = file.read()
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
2022-12-29 22:40:42 +03:00
|
|
|
def load_key(filename) -> "RsaKey":
|
|
|
|
try:
|
|
|
|
# Crypto | Cryptodome on Debian
|
|
|
|
from Crypto.PublicKey import RSA
|
|
|
|
from Crypto.PublicKey.RSA import RsaKey
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
from Cryptodome.PublicKey import RSA
|
|
|
|
from Cryptodome.PublicKey.RSA import RsaKey
|
|
|
|
|
2022-12-28 13:53:56 +03:00
|
|
|
return RSA.import_key(extern_key=load_file(filename), passphrase=None)
|
2022-12-28 16:30:42 +03:00
|
|
|
|
|
|
|
|
2023-06-12 16:19:06 +03:00
|
|
|
def parse_key(content: bytes) -> "RsaKey":
|
|
|
|
try:
|
|
|
|
# Crypto | Cryptodome on Debian
|
|
|
|
from Crypto.PublicKey import RSA
|
|
|
|
from Crypto.PublicKey.RSA import RsaKey
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
from Cryptodome.PublicKey import RSA
|
|
|
|
from Cryptodome.PublicKey.RSA import RsaKey
|
|
|
|
|
|
|
|
return RSA.import_key(extern_key=content, passphrase=None)
|
|
|
|
|
|
|
|
|
2022-12-29 22:40:42 +03:00
|
|
|
def generate_key() -> "RsaKey":
|
|
|
|
try:
|
|
|
|
# Crypto | Cryptodome on Debian
|
|
|
|
from Crypto.PublicKey import RSA
|
|
|
|
from Crypto.PublicKey.RSA import RsaKey
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
from Cryptodome.PublicKey import RSA
|
|
|
|
from Cryptodome.PublicKey.RSA import RsaKey
|
|
|
|
|
2022-12-28 16:30:42 +03:00
|
|
|
return RSA.generate(bits=2048)
|