mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Changes key encoding format from PEM to DER
This commit is contained in:
@@ -9,9 +9,9 @@ DEFAULT_PISA_API_PORT = 9814
|
||||
CLIENT_LOG_FILE = "pisa-cli.log"
|
||||
APPOINTMENTS_FOLDER_NAME = "appointments"
|
||||
|
||||
CLI_PUBLIC_KEY = "cli_pk.pem"
|
||||
CLI_PRIVATE_KEY = "cli_sk.pem"
|
||||
PISA_PUBLIC_KEY = "pisa_pk.pem"
|
||||
CLI_PUBLIC_KEY = "cli_pk.der"
|
||||
CLI_PRIVATE_KEY = "cli_sk.der"
|
||||
PISA_PUBLIC_KEY = "pisa_pk.der"
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
|
||||
@@ -7,27 +7,27 @@ from cryptography.hazmat.primitives.asymmetric import ec
|
||||
|
||||
|
||||
# Simple tool to generate an ECDSA private key using the secp256k1 curve and save private and public keys
|
||||
# as 'pisa_sk.pem' 'and pisa_pk.pem', respectively.
|
||||
# as 'pisa_sk.der' 'and pisa_pk.der', respectively.
|
||||
|
||||
SK_FILE_NAME = "pisa_sk.pem"
|
||||
PK_FILE_NAME = "pisa_pk.pem"
|
||||
SK_FILE_NAME = "../pisa_sk.der"
|
||||
PK_FILE_NAME = "../pisa_pk.der"
|
||||
|
||||
|
||||
def save_sk(sk, filename):
|
||||
pem = sk.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
der = sk.private_bytes(
|
||||
encoding=serialization.Encoding.DER,
|
||||
format=serialization.PrivateFormat.TraditionalOpenSSL,
|
||||
encryption_algorithm=serialization.NoEncryption(),
|
||||
)
|
||||
|
||||
with open(filename, "wb") as pem_out:
|
||||
pem_out.write(pem)
|
||||
with open(filename, "wb") as der_out:
|
||||
der_out.write(der)
|
||||
|
||||
|
||||
def save_pk(pk, filename):
|
||||
pem = pk.public_bytes(encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo)
|
||||
with open(filename, "wb") as pem_out:
|
||||
pem_out.write(pem)
|
||||
der = pk.public_bytes(encoding=serialization.Encoding.DER, format=serialization.PublicFormat.SubjectPublicKeyInfo)
|
||||
with open(filename, "wb") as der_out:
|
||||
der_out.write(der)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user