migrated from "cryptography" to "pycryptodome"

This commit is contained in:
Oscar Krause 2022-12-19 12:58:48 +01:00
parent 7042862600
commit fd73ac5f20
2 changed files with 9 additions and 17 deletions

View File

@ -1,6 +1,5 @@
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKeyWithSerialization from Crypto.PublicKey import RSA
from cryptography.hazmat.primitives.serialization import load_pem_private_key, Encoding, PrivateFormat, PublicFormat, \ from Crypto.PublicKey.RSA import RsaKey
NoEncryption
def load_file(filename) -> bytes: def load_file(filename) -> bytes:
@ -9,20 +8,13 @@ def load_file(filename) -> bytes:
return content return content
def load_key(filename) -> RSAPrivateKeyWithSerialization: def load_key(filename) -> RsaKey:
return load_pem_private_key(data=load_file(filename), password=None) return RSA.import_key(extern_key=load_file(filename), passphrase=None)
def private_bytes(rsa: RSAPrivateKeyWithSerialization) -> bytes: def private_bytes(rsa: RsaKey) -> bytes:
return rsa.private_bytes( return rsa.export_key(format='PEM', passphrase=None, protection=None)
encoding=Encoding.PEM,
format=PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=NoEncryption()
)
def public_key(rsa: RSAPrivateKeyWithSerialization) -> bytes: def public_key(rsa: RsaKey) -> bytes:
return rsa.public_key().public_bytes( return rsa.public_key().export_key(format='PEM')
encoding=Encoding.PEM,
format=PublicFormat.SubjectPublicKeyInfo
)

View File

@ -1,4 +1,4 @@
fastapi==0.88.0 fastapi==0.88.0
uvicorn[standard]==0.20.0 uvicorn[standard]==0.20.0
python-jose==3.3.0 python-jose==3.3.0
cryptography==38.0.4 pycryptodome==3.16.0