CryptoKeyPair

Bases: BaseModel

Represents a cryptographic key pair.

Parameters:
  • private_key

    The private key

  • public_key

    The public key

generate abstractmethod classmethod
generate(*args) -> CryptoKeyPair

Abstract method to generate a cryptographic key pair.

Returns:

CryptoPrivateKey

Bases: InitCryptoParser, abc.ABC

Represents a cryptographic private key.

der_bytes property
der_bytes: bytes

Property to get the DER encoding of the public key.

Returns:
  • bytes( bytes ) –

    The DER encoded public key.

pem_bytes property
pem_bytes: bytes

Property to get the PEM encoding of the private key.

Returns:
  • bytes( bytes ) –

    The PEM encoded private key.

from_cryptography classmethod
from_cryptography(key: CertificateIssuerPrivateKeyTypes) -> CryptoPrivateKey

Create a CryptoPrivateKey from a cryptography private key.

Parameters:
Returns:

CryptoPublicKey

Bases: InitCryptoParser, abc.ABC

Represents a cryptographic public key.

der_bytes property
der_bytes: bytes

Property to get the DER encoding of the public key.

Returns:
  • bytes( bytes ) –

    The DER encoded public key.

ocsp_bytes property
ocsp_bytes: bytes

The bytes used for the OCSP Response hash

Returns:
  • bytes( bytes ) –

    The bytes used for the OCSP Response hash

pem_bytes property
pem_bytes: bytes

Property to get the PEM encoding of the public key.

Returns:
  • bytes( bytes ) –

    The PEM encoded public key.

from_cryptography classmethod
from_cryptography(key: CertificateIssuerPublicKeyTypes) -> CryptoPublicKey

Create a CryptoPublicKey from a cryptography public key.

Parameters:
Returns:
verify abstractmethod
verify(signed: InitCryptoParser) -> None

Verifies the signature of a signed object.

Parameters:

DSAKeyPair

Bases: CryptoKeyPair

Describes a DSA Key Pair including the public and private DSA keys.

Note

DSA is an old and legacy algorithm. Consider using EllipticCurveKeyPair or RSAKeyPair instead.

Examples
Generate keypair
from pki_tools import DSAKeyPair

key_pair = DSAKeyPair.generate(key_size=1024)

print(key_pair.private_key.pem_string)
print(key_pair.public_key.pem_string)
Print output
-----BEGIN DSA PRIVATE KEY-----
MIIBvAIBAAKBgQD43Od5Ib9Gf7zn3BqonOwCMvmWw3QBVSkcIIPtfjoPCF5eZUkE
+N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Kl2LVp1NXxZLMA7sKy+2g6
k3yuI65VieTAtvnh9zg+y53+XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62
uFDny0lY6Ow+47ZK
-----END PUBLIC KEY-----

InitCryptoParser.from_cryptography
crypto_keys
from cryptography.hazmat.primitives import serialization

private_key_pem = b"""
-----BEGIN DSA PRIVATE KEY-----
MIIBvAIBAAKBgQD43Od5Ib9Gf7zn3BqonOwCMvmWw3QBVSkcIIPtfjoPCF5eZUkE
+NxkC+8TVLFP6BirpwifJsUyD2SOZre2JtF3SUmKFiPhS3934suqEWHpedeZy8Dy
2g7yuqU3OiOMU06iRemDhcWJmCp3MEF5N321Eh66t9yq5oN1iYbnRkvxFQIVANAA
0DyNl0WkdNjOwKRXKtRtgf5zAoGBAKIGG/O5f1FbUmhBK0z2jZLYvup3CKSMYvJL
ztDMSjDW1NTuht0qQLszEso82SwtuYRRAvpezwkWKhQSj2fo+Dg+A8+4Rc6N9oMO
f0ZM4BOGdkm4WEKpIArx9wEYamHpGuIYSER0ygbw/vQD0fjG24FxhBKCkd7F1pf9
+ervHU/gAoGBANSn6Svi4CZns0W5Uv3yzR9+4jjUDXaHq3/1cCaAuKJF5jR7OlTf
e+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6k3yuI65VieTAtvnh9zg+y53+
XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62uFDny0lY6Ow+47ZKAhRtGeN4
19EKC+vetSlF1/ORPoDQ2A==
-----END DSA PRIVATE KEY-----
"""
public_key_pem = b"""
-----BEGIN PUBLIC KEY-----
MIIBuDCCASwGByqGSM44BAEwggEfAoGBAPjc53khv0Z/vOfcGqic7AIy+ZbDdAFV
KRwgg+1+Og8IXl5lSQT43GQL7xNUsU/oGKunCJ8mxTIPZI5mt7Ym0XdJSYoWI+FL
f3fiy6oRYel515nLwPLaDvK6pTc6I4xTTqJF6YOFxYmYKncwQXk3fbUSHrq33Krm
g3WJhudGS/EVAhUA0ADQPI2XRaR02M7ApFcq1G2B/nMCgYEAogYb87l/UVtSaEEr
TPaNkti+6ncIpIxi8kvO0MxKMNbU1O6G3SpAuzMSyjzZLC25hFEC+l7PCRYqFBKP
Z+j4OD4Dz7hFzo32gw5/RkzgE4Z2SbhYQqkgCvH3ARhqYeka4hhIRHTKBvD+9APR
+MbbgXGEEoKR3sXWl/356u8dT+ADgYUAAoGBANSn6Svi4CZns0W5Uv3yzR9+4jjU
DXaHq3/1cCaAuKJF5jR7OlTfe+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6
k3yuI65VieTAtvnh9zg+y53+XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62
uFDny0lY6Ow+47ZK
-----END PUBLIC KEY-----
"""

crypto_public_key = serialization.load_pem_public_key(public_key_pem)
crypto_private_key = serialization.load_pem_private_key(
    private_key_pem, password=None
)
from pki_tools import DSAKeyPair, DSAPublicKey, DSAPrivateKey

key_pair = DSAKeyPair(
    public_key=DSAPublicKey.from_cryptography(crypto_public_key),
    private_key=DSAPrivateKey.from_cryptography(crypto_private_key),
)

print(key_pair)
Print output
DSAKeyPair:
  generator_g: '113777026571325530148150394408467299305589997194470431376564940585605453797253843240385953561624361715300637770674134020122595656184354455315207866000987394828535805614606024021315033549457672053549361497135203471795738563110933341121849876449932177135069371874058966749891793319752800046614670106059201138656'
  key_size: '1024'
  prime_p: '174757476342306797247563317256894129844245132954515284483435018210595536104310937495384232315831853480443453499620885651911198721759647573944694709015221077111398208541814382944481887170189910067356212345671285839418487207597130726845228782300695389126938410647911854140920564564816908606042285402918736359701'
  public_key_y: '149332052542478152219821166226616716616977242473328582848563249300540754897324006416792998195121332611269937769202630005073559668943384310360257482112770686017742010665852185709674377535585104122942880303444668338707692502260752201470105621604193468478471725786623824002451061035867177729841769129384287123018'
  subprime_q: '1187488220291981039175259798988933546327060643443'

InitCryptoParser.from_file
private.pem
-----BEGIN DSA PRIVATE KEY-----
MIIBvAIBAAKBgQD43Od5Ib9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yzR9+4jjU
DXaHq3/1cCaAuKJF5jR7OlTfe+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6
k3yuI65VieTAtvnh9zg+y53+XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62
uFDny0lY6Ow+47ZK
-----END PUBLIC KEY-----
from pki_tools import DSAKeyPair, DSAPublicKey, DSAPrivateKey

key_pair = DSAKeyPair(
    public_key=DSAPublicKey.from_file("public.pem"),
    private_key=DSAPrivateKey.from_file("private.pem"),
)

print(key_pair)
Print output
DSAKeyPair:
  generator_g: '113777026571325530148150394408467299305589997194470431376564940585605453797253843240385953561624361715300637770674134020122595656184354455315207866000987394828535805614606024021315033549457672053549361497135203471795738563110933341121849876449932177135069371874058966749891793319752800046614670106059201138656'
  key_size: '1024'
  prime_p: '174757476342306797247563317256894129844245132954515284483435018210595536104310937495384232315831853480443453499620885651911198721759647573944694709015221077111398208541814382944481887170189910067356212345671285839418487207597130726845228782300695389126938410647911854140920564564816908606042285402918736359701'
  public_key_y: '149332052542478152219821166226616716616977242473328582848563249300540754897324006416792998195121332611269937769202630005073559668943384310360257482112770686017742010665852185709674377535585104122942880303444668338707692502260752201470105621604193468478471725786623824002451061035867177729841769129384287123018'
  subprime_q: '1187488220291981039175259798988933546327060643443'

InitCryptoParser.from_pem_string
private_pem
private_pem = """
-----BEGIN DSA PRIVATE KEY-----
MIIBvAIBAAKBgQD43Od5Ib9Gf7zn3BqonOwCMvmWw3QBVSkcIIPtfjoPCF5eZUkE
+NxkC+8TVLFP6BirpwifJsUyD2SOZre2JtF3SUmKFiPhS3934suqEWHpedeZy8Dy
2g7yuqU3OiOMU06iRemDhcWJmCp3MEF5N321Eh66t9yq5oN1iYbnRkvxFQIVANAA
0DyNl0WkdNjOwKRXKtRtgf5zAoGBAKIGG/O5f1FbUmhBK0z2jZLYvup3CKSMYvJL
ztDMSjDW1NTuht0qQLszEso82SwtuYRRAvpezwkWKhQSj2fo+Dg+A8+4Rc6N9oMO
f0ZM4BOGdkm4WEKpIArx9wEYamHpGuIYSER0ygbw/vQD0fjG24FxhBKCkd7F1pf9
+ervHU/gAoGBANSn6Svi4CZns0W5Uv3yzR9+4jjUDXaHq3/1cCaAuKJF5jR7OlTf
e+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6k3yuI65VieTAtvnh9zg+y53+
XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62uFDny0lY6Ow+47ZKAhRtGeN4
19EKC+vetSlF1/ORPoDQ2A==
-----END DSA PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MIIBuDCCASwGByqGSM44BAEwggEfAoGBAPjc53khv0Z/vOfcGqic7AIy+ZbDdAFV
KRwgg+1+Og8IXl5lSQT43GQL7xNUsU/oGKunCJ8mxTIPZI5mt7Ym0XdJSYoWI+FL
f3fiy6oRYel515nLwPLaDvK6pTc6I4xTTqJF6YOFxYmYKncwQXk3fbUSHrq33Krm
g3WJhudGS/EVAhUA0ADQPI2XRaR02M7ApFcq1G2B/nMCgYEAogYb87l/UVtSaEEr
TPaNkti+6ncIpIxi8kvO0MxKMNbU1O6G3SpAuzMSyjzZLC25hFEC+l7PCRYqFBKP
Z+j4OD4Dz7hFzo32gw5/RkzgE4Z2SbhYQqkgCvH3ARhqYeka4hhIRHTKBvD+9APR
+MbbgXGEEoKR3sXWl/356u8dT+ADgYUAAoGBANSn6Svi4CZns0W5Uv3yzR9+4jjU
DXaHq3/1cCaAuKJF5jR7OlTfe+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6
k3yuI65VieTAtvnh9zg+y53+XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62
uFDny0lY6Ow+47ZK
-----END PUBLIC KEY-----
"""
from pki_tools import DSAKeyPair, DSAPublicKey, DSAPrivateKey

key_pair = DSAKeyPair(
    public_key=DSAPublicKey.from_pem_string(public_pem),
    private_key=DSAPrivateKey.from_pem_string(private_pem),
)

print(key_pair)
Print output
DSAKeyPair:
  generator_g: '113777026571325530148150394408467299305589997194470431376564940585605453797253843240385953561624361715300637770674134020122595656184354455315207866000987394828535805614606024021315033549457672053549361497135203471795738563110933341121849876449932177135069371874058966749891793319752800046614670106059201138656'
  key_size: '1024'
  prime_p: '174757476342306797247563317256894129844245132954515284483435018210595536104310937495384232315831853480443453499620885651911198721759647573944694709015221077111398208541814382944481887170189910067356212345671285839418487207597130726845228782300695389126938410647911854140920564564816908606042285402918736359701'
  public_key_y: '149332052542478152219821166226616716616977242473328582848563249300540754897324006416792998195121332611269937769202630005073559668943384310360257482112770686017742010665852185709674377535585104122942880303444668338707692502260752201470105621604193468478471725786623824002451061035867177729841769129384287123018'
  subprime_q: '1187488220291981039175259798988933546327060643443'

InitCryptoParser.to_file
private_pem
private_pem = """
-----BEGIN DSA PRIVATE KEY-----
MIIBvAIBAAKBgQD43Od5Ib9Gf7zn3BqonOwCMvmWw3QBVSkcIIPtfjoPCF5eZUkE
+NxkC+8TVLFP6BirpwifJsUyD2SOZre2JtF3SUmKFiPhS3934suqEWHpedeZy8Dy
2g7yuqU3OiOMU06iRemDhcWJmCp3MEF5N321Eh66t9yq5oN1iYbnRkvxFQIVANAA
0DyNl0WkdNjOwKRXKtRtgf5zAoGBAKIGG/O5f1FbUmhBK0z2jZLYvup3CKSMYvJL
ztDMSjDW1NTuht0qQLszEso82SwtuYRRAvpezwkWKhQSj2fo+Dg+A8+4Rc6N9oMO
f0ZM4BOGdkm4WEKpIArx9wEYamHpGuIYSER0ygbw/vQD0fjG24FxhBKCkd7F1pf9
+ervHU/gAoGBANSn6Svi4CZns0W5Uv3yzR9+4jjUDXaHq3/1cCaAuKJF5jR7OlTf
e+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6k3yuI65VieTAtvnh9zg+y53+
XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62uFDny0lY6Ow+47ZKAhRtGeN4
19EKC+vetSlF1/ORPoDQ2A==
-----END DSA PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MIIBuDCCASwGByqGSM44BAEwggEfAoGBAPjc53khv0Z/vOfcGqic7AIy+ZbDdAFV
KRwgg+1+Og8IXl5lSQT43GQL7xNUsU/oGKunCJ8mxTIPZI5mt7Ym0XdJSYoWI+FL
f3fiy6oRYel515nLwPLaDvK6pTc6I4xTTqJF6YOFxYmYKncwQXk3fbUSHrq33Krm
g3WJhudGS/EVAhUA0ADQPI2XRaR02M7ApFcq1G2B/nMCgYEAogYb87l/UVtSaEEr
TPaNkti+6ncIpIxi8kvO0MxKMNbU1O6G3SpAuzMSyjzZLC25hFEC+l7PCRYqFBKP
Z+j4OD4Dz7hFzo32gw5/RkzgE4Z2SbhYQqkgCvH3ARhqYeka4hhIRHTKBvD+9APR
+MbbgXGEEoKR3sXWl/356u8dT+ADgYUAAoGBANSn6Svi4CZns0W5Uv3yzR9+4jjU
DXaHq3/1cCaAuKJF5jR7OlTfe+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6
k3yuI65VieTAtvnh9zg+y53+XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62
uFDny0lY6Ow+47ZK
-----END PUBLIC KEY-----
"""
from pki_tools import DSAKeyPair, DSAPublicKey, DSAPrivateKey

key_pair = DSAKeyPair(
    public_key=DSAPublicKey.from_pem_string(public_pem),
    private_key=DSAPrivateKey.from_pem_string(private_pem),
)

key_pair.public_key.to_file("out_public.pem")
key_pair.private_key.to_file("out_private.pem")
out_private.pem
-----BEGIN DSA PRIVATE KEY-----
MIIBvAIBAAKBgQD43Od5Ib9Gf7zn3BqonOwCMvmWw3QBVSkcIIPtfjoPCF5eZUkE
+NxkC+8TVLFP6BirpwifJsUyD2SOZre2JtF3SUmKFiPhS3934suqEWHpedeZy8Dy
2g7yuqU3OiOMU06iRemDhcWJmCp3MEF5N321Eh66t9yq5oN1iYbnRkvxFQIVANAA
0DyNl0WkdNjOwKRXKtRtgf5zAoGBAKIGG/O5f1FbUmhBK0z2jZLYvup3CKSMYvJL
ztDMSjDW1NTuht0qQLszEso82SwtuYRRAvpezwkWKhQSj2fo+Dg+A8+4Rc6N9oMO
f0ZM4BOGdkm4WEKpIArx9wEYamHpGuIYSER0ygbw/vQD0fjG24FxhBKCkd7F1pf9
+ervHU/gAoGBANSn6Svi4CZns0W5Uv3yzR9+4jjUDXaHq3/1cCaAuKJF5jR7OlTf
e+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6k3yuI65VieTAtvnh9zg+y53+
XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62uFDny0lY6Ow+47ZKAhRtGeN4
19EKC+vetSlF1/ORPoDQ2A==
-----END DSA PRIVATE KEY-----
out_public.pem
-----BEGIN PUBLIC KEY-----
MIIBuDCCASwGByqGSM44BAEwggEfAoGBAPjc53khv0Z/vOfcGqic7AIy+ZbDdAFV
KRwgg+1+Og8IXl5lSQT43GQL7xNUsU/oGKunCJ8mxTIPZI5mt7Ym0XdJSYoWI+FL
f3fiy6oRYel515nLwPLaDvK6pTc6I4xTTqJF6YOFxYmYKncwQXk3fbUSHrq33Krm
g3WJhudGS/EVAhUA0ADQPI2XRaR02M7ApFcq1G2B/nMCgYEAogYb87l/UVtSaEEr
TPaNkti+6ncIpIxi8kvO0MxKMNbU1O6G3SpAuzMSyjzZLC25hFEC+l7PCRYqFBKP
Z+j4OD4Dz7hFzo32gw5/RkzgE4Z2SbhYQqkgCvH3ARhqYeka4hhIRHTKBvD+9APR
+MbbgXGEEoKR3sXWl/356u8dT+ADgYUAAoGBANSn6Svi4CZns0W5Uv3yzR9+4jjU
DXaHq3/1cCaAuKJF5jR7OlTfe+n1IZCrPSshMF210wKl2LVp1NXxZLMA7sKy+2g6
k3yuI65VieTAtvnh9zg+y53+XxyYrJYvKRUmYqIluUvVDiJCJlYZdcZfgOP68v62
uFDny0lY6Ow+47ZK
-----END PUBLIC KEY-----
generate classmethod
generate(key_size: int) -> DSAKeyPair

Generate a DSA cryptographic key pair.

Parameters:
  • key_size (int) –

    The size of the key.

Returns:

DSAPrivateKey

Bases: CryptoPrivateKey

Represents a DSA cryptographic private key.

from_cryptography classmethod
from_cryptography(key: dsa.DSAPrivateKey) -> DSAPrivateKey

Create a DSAPrivateKey from a cryptography key.

Parameters:
Returns:

DSAPublicKey

Bases: CryptoPublicKey

Represents a DSA cryptographic key pair.

ocsp_bytes property
ocsp_bytes: bytes

The bytes used for the OCSP Response hash

Returns:
  • bytes( bytes ) –

    The bytes used for the OCSP Response hash

from_cryptography classmethod
from_cryptography(key: dsa.DSAPublicKey) -> DSAPublicKey

Create a DSAKeyPair from a cryptography key.

Parameters:
Returns:

Ed25519KeyPair

Bases: CryptoKeyPair

Represents an Ed25519 cryptographic key pair.

Examples
Generate keypair
from pki_tools import Ed25519KeyPair

key_pair = Ed25519KeyPair.generate()

print(key_pair.private_key.pem_string)
print(key_pair.public_key.pem_string)
Print output
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIK1Rmqg3vSeNU/VcGCcp6v9jg2Wc4oQOsZUX7UboRrIL
-----END PRIVATE KEY-----

-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAwz9uDUJ3qeYcok1CoMAbfiJrZT7PlT3wtLZwf+wlhho=
-----END PUBLIC KEY-----

InitCryptoParser.from_cryptography
crypto_keys
from cryptography.hazmat.primitives import serialization

private_key_pem = b"""
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIK1Rmqg3vSeNU/VcGCcp6v9jg2Wc4oQOsZUX7UboRrIL
-----END PRIVATE KEY-----
"""
public_key_pem = b"""
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAwz9uDUJ3qeYcok1CoMAbfiJrZT7PlT3wtLZwf+wlhho=
-----END PUBLIC KEY-----
"""

crypto_public_key = serialization.load_pem_public_key(public_key_pem)
crypto_private_key = serialization.load_pem_private_key(
    private_key_pem, password=None
)
from pki_tools import Ed25519KeyPair, Ed25519PublicKey, Ed25519PrivateKey

key_pair = Ed25519KeyPair(
    public_key=Ed25519PublicKey.from_cryptography(crypto_public_key),
    private_key=Ed25519PrivateKey.from_cryptography(crypto_private_key),
)

print(key_pair)
Print output
Ed25519KeyPair:
  public_bytes: C33F6E0D4277A9E61CA24D42A0C01B7E226B653ECF953DF0B4B6707FEC25861A

InitCryptoParser.from_file
private.pem
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIK1Rmqg3vSeNU/VcGCcp6v9jg2Wc4oQOsZUX7UboRrIL
-----END PRIVATE KEY-----
public.pem
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAwz9uDUJ3qeYcok1CoMAbfiJrZT7PlT3wtLZwf+wlhho=
-----END PUBLIC KEY-----
from pki_tools import Ed25519KeyPair, Ed25519PublicKey, Ed25519PrivateKey

key_pair = Ed25519KeyPair(
    public_key=Ed25519PublicKey.from_file("public.pem"),
    private_key=Ed25519PrivateKey.from_file("private.pem"),
)

print(key_pair)
Print output
Ed25519KeyPair:
  public_bytes: C33F6E0D4277A9E61CA24D42A0C01B7E226B653ECF953DF0B4B6707FEC25861A

InitCryptoParser.from_pem_string
private_pem
private_pem = """
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIK1Rmqg3vSeNU/VcGCcp6v9jg2Wc4oQOsZUX7UboRrIL
-----END PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAwz9uDUJ3qeYcok1CoMAbfiJrZT7PlT3wtLZwf+wlhho=
-----END PUBLIC KEY-----
"""
from pki_tools import Ed25519KeyPair, Ed25519PublicKey, Ed25519PrivateKey

key_pair = Ed25519KeyPair(
    public_key=Ed25519PublicKey.from_pem_string(public_pem),
    private_key=Ed25519PrivateKey.from_pem_string(private_pem),
)

print(key_pair)
Print output
Ed25519KeyPair:
  public_bytes: C33F6E0D4277A9E61CA24D42A0C01B7E226B653ECF953DF0B4B6707FEC25861A

InitCryptoParser.to_file
private_pem
private_pem = """
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIK1Rmqg3vSeNU/VcGCcp6v9jg2Wc4oQOsZUX7UboRrIL
-----END PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAwz9uDUJ3qeYcok1CoMAbfiJrZT7PlT3wtLZwf+wlhho=
-----END PUBLIC KEY-----
"""
from pki_tools import Ed25519KeyPair, Ed25519PublicKey, Ed25519PrivateKey

key_pair = Ed25519KeyPair(
    public_key=Ed25519PublicKey.from_pem_string(public_pem),
    private_key=Ed25519PrivateKey.from_pem_string(private_pem),
)

key_pair.public_key.to_file("out_public.pem")
key_pair.private_key.to_file("out_private.pem")
out_private.pem
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIK1Rmqg3vSeNU/VcGCcp6v9jg2Wc4oQOsZUX7UboRrIL
-----END PRIVATE KEY-----
out_public.pem
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAwz9uDUJ3qeYcok1CoMAbfiJrZT7PlT3wtLZwf+wlhho=
-----END PUBLIC KEY-----
generate classmethod
generate() -> Ed25519KeyPair

Generate an Ed25519KeyPair cryptographic key pair.

Returns:

Ed25519PrivateKey

Bases: CryptoPrivateKey

from_cryptography classmethod
from_cryptography(key: ed25519.Ed25519PrivateKey) -> Ed25519PrivateKey

Create an Ed25519 private key from a cryptography private key.

Parameters:
Returns:

Ed25519PublicKey

Bases: CryptoPublicKey

from_cryptography classmethod
from_cryptography(key: ed25519.Ed25519PublicKey) -> Ed25519PublicKey

Create an Ed25519PublicKey from a cryptography public key.

Parameters:
Returns:

Ed448KeyPair

Bases: CryptoKeyPair

Represents an Ed448 cryptographic key pair.

Examples
Generate keypair
from pki_tools import Ed448KeyPair

key_pair = Ed448KeyPair.generate()

print(key_pair.private_key.pem_string)
print(key_pair.public_key.pem_string)
Print output
-----BEGIN PRIVATE KEY-----
MEcCAQAwBQYDK2VxBDsEOddX4ESZ5SsmiX/VMUPbnpPs/OOG4/zGvm4H5mN3nDTn
aueR56mFimzXxc7tj3z+N1lmNeO23ZNFPA==
-----END PRIVATE KEY-----

-----BEGIN PUBLIC KEY-----
MEMwBQYDK2VxAzoAfCdaj7HXSPMqW+Tl+lXEzItOzK2AoZjkvcCMR+gepngd0mDy
KbC4U+fVnxnbf1UuJxFiARSUjUWA
-----END PUBLIC KEY-----

InitCryptoParser.from_cryptography
crypto_keys
from cryptography.hazmat.primitives import serialization

private_key_pem = b"""
-----BEGIN PRIVATE KEY-----
MEcCAQAwBQYDK2VxBDsEOddX4ESZ5SsmiX/VMUPbnpPs/OOG4/zGvm4H5mN3nDTn
aueR56mFimzXxc7tj3z+N1lmNeO23ZNFPA==
-----END PRIVATE KEY-----
"""
public_key_pem = b"""
-----BEGIN PUBLIC KEY-----
MEMwBQYDK2VxAzoAfCdaj7HXSPMqW+Tl+lXEzItOzK2AoZjkvcCMR+gepngd0mDy
KbC4U+fVnxnbf1UuJxFiARSUjUWA
-----END PUBLIC KEY-----
"""

crypto_public_key = serialization.load_pem_public_key(public_key_pem)
crypto_private_key = serialization.load_pem_private_key(
    private_key_pem, password=None
)
from pki_tools import Ed448KeyPair, Ed448PublicKey, Ed448PrivateKey

key_pair = Ed448KeyPair(
    public_key=Ed448PublicKey.from_cryptography(crypto_public_key),
    private_key=Ed448PrivateKey.from_cryptography(crypto_private_key),
)

print(key_pair)
Print output
Ed448KeyPair:
  public_bytes: 7C275A8FB1D748F32A5BE4E5FA55C4CC8B4ECCAD80A198E4BDC08C47E81EA6781DD260F229B0B853E7D59F19DB7F552E2711620114948D4580

InitCryptoParser.from_file
private.pem
-----BEGIN PRIVATE KEY-----
MEcCAQAwBQYDK2VxBDsEOddX4ESZ5SsmiX/VMUPbnpPs/OOG4/zGvm4H5mN3nDTn
aueR56mFimzXxc7tj3z+N1lmNeO23ZNFPA==
-----END PRIVATE KEY-----
public.pem
-----BEGIN PUBLIC KEY-----
MEMwBQYDK2VxAzoAfCdaj7HXSPMqW+Tl+lXEzItOzK2AoZjkvcCMR+gepngd0mDy
KbC4U+fVnxnbf1UuJxFiARSUjUWA
-----END PUBLIC KEY-----
from pki_tools import Ed448KeyPair, Ed448PublicKey, Ed448PrivateKey

key_pair = Ed448KeyPair(
    public_key=Ed448PublicKey.from_file("public.pem"),
    private_key=Ed448PrivateKey.from_file("private.pem"),
)

print(key_pair)
Print output
Ed448KeyPair:
  public_bytes: 7C275A8FB1D748F32A5BE4E5FA55C4CC8B4ECCAD80A198E4BDC08C47E81EA6781DD260F229B0B853E7D59F19DB7F552E2711620114948D4580

InitCryptoParser.from_pem_string
private_pem
private_pem = """
-----BEGIN PRIVATE KEY-----
MEcCAQAwBQYDK2VxBDsEOddX4ESZ5SsmiX/VMUPbnpPs/OOG4/zGvm4H5mN3nDTn
aueR56mFimzXxc7tj3z+N1lmNeO23ZNFPA==
-----END PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MEMwBQYDK2VxAzoAfCdaj7HXSPMqW+Tl+lXEzItOzK2AoZjkvcCMR+gepngd0mDy
KbC4U+fVnxnbf1UuJxFiARSUjUWA
-----END PUBLIC KEY-----
"""
from pki_tools import Ed448KeyPair, Ed448PublicKey, Ed448PrivateKey

key_pair = Ed448KeyPair(
    public_key=Ed448PublicKey.from_pem_string(public_pem),
    private_key=Ed448PrivateKey.from_pem_string(private_pem),
)

print(key_pair)
Print output
Ed448KeyPair:
  public_bytes: 7C275A8FB1D748F32A5BE4E5FA55C4CC8B4ECCAD80A198E4BDC08C47E81EA6781DD260F229B0B853E7D59F19DB7F552E2711620114948D4580

InitCryptoParser.to_file
private_pem
private_pem = """
-----BEGIN PRIVATE KEY-----
MEcCAQAwBQYDK2VxBDsEOddX4ESZ5SsmiX/VMUPbnpPs/OOG4/zGvm4H5mN3nDTn
aueR56mFimzXxc7tj3z+N1lmNeO23ZNFPA==
-----END PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MEMwBQYDK2VxAzoAfCdaj7HXSPMqW+Tl+lXEzItOzK2AoZjkvcCMR+gepngd0mDy
KbC4U+fVnxnbf1UuJxFiARSUjUWA
-----END PUBLIC KEY-----
"""
from pki_tools import Ed448KeyPair, Ed448PublicKey, Ed448PrivateKey

key_pair = Ed448KeyPair(
    public_key=Ed448PublicKey.from_pem_string(public_pem),
    private_key=Ed448PrivateKey.from_pem_string(private_pem),
)

key_pair.public_key.to_file("out_public.pem")
key_pair.private_key.to_file("out_private.pem")
out_private.pem
-----BEGIN PRIVATE KEY-----
MEcCAQAwBQYDK2VxBDsEOddX4ESZ5SsmiX/VMUPbnpPs/OOG4/zGvm4H5mN3nDTn
aueR56mFimzXxc7tj3z+N1lmNeO23ZNFPA==
-----END PRIVATE KEY-----
out_public.pem
-----BEGIN PUBLIC KEY-----
MEMwBQYDK2VxAzoAfCdaj7HXSPMqW+Tl+lXEzItOzK2AoZjkvcCMR+gepngd0mDy
KbC4U+fVnxnbf1UuJxFiARSUjUWA
-----END PUBLIC KEY-----
generate classmethod
generate() -> Ed448KeyPair

Generate an Ed448 cryptographic key pair.

Returns:

Ed448PrivateKey

Bases: CryptoPrivateKey

from_cryptography classmethod
from_cryptography(key: ed448.Ed448PrivateKey) -> Ed448PrivateKey

Create an Ed25519KeyPair from a cryptography private key.

Parameters:
Returns:

Ed448PublicKey

Bases: CryptoPublicKey

from_cryptography classmethod
from_cryptography(key: ed448.Ed448PublicKey) -> Ed448PublicKey

Create an Ed448PublicKey from a cryptography public key.

Parameters:
Returns:

EllipticCurveKeyPair

Bases: CryptoKeyPair

Describes an elliptic curve Key Pair including the public and private keys.

Examples
Generate keypair
from pki_tools import EllipticCurveKeyPair, EllipticCurveName

key_pair = EllipticCurveKeyPair.generate(
    curve_name=EllipticCurveName.SECP521R1
)

print(key_pair.private_key.pem_string)
print(key_pair.public_key.pem_string)
Print output
-----BEGIN EC PRIVATE KEY-----
MF8CAQEEGKjPz1HxOsCzWDldL2lBRkhNn8BeANbriaAKBggqhkjOPQMBAaE0AzIA
BJ32je0cT4KuCA13aM56xkUnEFGukuHAMU6cWJhInPl95dkcRhs+U8ZrUGO9jFaR
kg==
-----END EC PRIVATE KEY-----

-----BEGIN PUBLIC KEY-----
MEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEnfaN7RxPgq4IDXdoznrGRScQUa6S
4cAxTpxYmEic+X3l2RxGGz5TxmtQY72MVpGS
-----END PUBLIC KEY-----

InitCryptoParser.from_cryptography
crypto_keys
from cryptography.hazmat.primitives import serialization

private_key_pem = b"""
-----BEGIN EC PRIVATE KEY-----
MF8CAQEEGKjPz1HxOsCzWDldL2lBRkhNn8BeANbriaAKBggqhkjOPQMBAaE0AzIA
BJ32je0cT4KuCA13aM56xkUnEFGukuHAMU6cWJhInPl95dkcRhs+U8ZrUGO9jFaR
kg==
-----END EC PRIVATE KEY-----
"""
public_key_pem = b"""
-----BEGIN PUBLIC KEY-----
MEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEnfaN7RxPgq4IDXdoznrGRScQUa6S
4cAxTpxYmEic+X3l2RxGGz5TxmtQY72MVpGS
-----END PUBLIC KEY-----
"""

crypto_public_key = serialization.load_pem_public_key(public_key_pem)
crypto_private_key = serialization.load_pem_private_key(
    private_key_pem, password=None
)
from pki_tools import (
    EllipticCurveKeyPair,
    EllipticCurvePublicKey,
    EllipticCurvePrivateKey,
)

key_pair = EllipticCurveKeyPair(
    public_key=EllipticCurvePublicKey.from_cryptography(crypto_public_key),
    private_key=EllipticCurvePrivateKey.from_cryptography(crypto_private_key),
)

print(key_pair)
Print output
EllipticCurveKeyPair:
  curve_name: SECP192R1
  x_coordinate: '3873244018496539881359912556942920160767430416289115521073'
  y_coordinate: '1927529413795754362028696442258815769538381786197708411282'

InitCryptoParser.from_file
private.pem
-----BEGIN EC PRIVATE KEY-----
MF8CAQEEGKjPz1HxOsCzWDldL2lBRkhNn8BeANbriaAKBggqhkjOPQMBAaE0AzIA
BJ32je0cT4KuCA13aM56xkUnEFGukuHAMU6cWJhInPl95dkcRhs+U8ZrUGO9jFaR
kg==
-----END EC PRIVATE KEY-----
public.pem
-----BEGIN PUBLIC KEY-----
MEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEnfaN7RxPgq4IDXdoznrGRScQUa6S
4cAxTpxYmEic+X3l2RxGGz5TxmtQY72MVpGS
-----END PUBLIC KEY-----
from pki_tools import (
    EllipticCurveKeyPair,
    EllipticCurvePublicKey,
    EllipticCurvePrivateKey,
)

key_pair = EllipticCurveKeyPair(
    public_key=EllipticCurvePublicKey.from_file("public.pem"),
    private_key=EllipticCurvePrivateKey.from_file("private.pem"),
)

print(key_pair)
Print output
EllipticCurveKeyPair:
  curve_name: SECP192R1
  x_coordinate: '3873244018496539881359912556942920160767430416289115521073'
  y_coordinate: '1927529413795754362028696442258815769538381786197708411282'

InitCryptoParser.from_pem_string
private_pem
private_pem = """
-----BEGIN EC PRIVATE KEY-----
MF8CAQEEGKjPz1HxOsCzWDldL2lBRkhNn8BeANbriaAKBggqhkjOPQMBAaE0AzIA
BJ32je0cT4KuCA13aM56xkUnEFGukuHAMU6cWJhInPl95dkcRhs+U8ZrUGO9jFaR
kg==
-----END EC PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEnfaN7RxPgq4IDXdoznrGRScQUa6S
4cAxTpxYmEic+X3l2RxGGz5TxmtQY72MVpGS
-----END PUBLIC KEY-----
"""
from pki_tools import (
    EllipticCurveKeyPair,
    EllipticCurvePublicKey,
    EllipticCurvePrivateKey,
)

key_pair = EllipticCurveKeyPair(
    public_key=EllipticCurvePublicKey.from_pem_string(public_pem),
    private_key=EllipticCurvePrivateKey.from_pem_string(private_pem),
)

print(key_pair)
Print output
EllipticCurveKeyPair:
  curve_name: SECP192R1
  x_coordinate: '3873244018496539881359912556942920160767430416289115521073'
  y_coordinate: '1927529413795754362028696442258815769538381786197708411282'

InitCryptoParser.to_file
private_pem
private_pem = """
-----BEGIN EC PRIVATE KEY-----
MF8CAQEEGKjPz1HxOsCzWDldL2lBRkhNn8BeANbriaAKBggqhkjOPQMBAaE0AzIA
BJ32je0cT4KuCA13aM56xkUnEFGukuHAMU6cWJhInPl95dkcRhs+U8ZrUGO9jFaR
kg==
-----END EC PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEnfaN7RxPgq4IDXdoznrGRScQUa6S
4cAxTpxYmEic+X3l2RxGGz5TxmtQY72MVpGS
-----END PUBLIC KEY-----
"""
from pki_tools import (
    EllipticCurveKeyPair,
    EllipticCurvePublicKey,
    EllipticCurvePrivateKey,
)

key_pair = EllipticCurveKeyPair(
    public_key=EllipticCurvePublicKey.from_pem_string(public_pem),
    private_key=EllipticCurvePrivateKey.from_pem_string(private_pem),
)

key_pair.public_key.to_file("out_public.pem")
key_pair.private_key.to_file("out_private.pem")
out_private.pem
-----BEGIN EC PRIVATE KEY-----
MF8CAQEEGKjPz1HxOsCzWDldL2lBRkhNn8BeANbriaAKBggqhkjOPQMBAaE0AzIA
BJ32je0cT4KuCA13aM56xkUnEFGukuHAMU6cWJhInPl95dkcRhs+U8ZrUGO9jFaR
kg==
-----END EC PRIVATE KEY-----
out_public.pem
-----BEGIN PUBLIC KEY-----
MEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEnfaN7RxPgq4IDXdoznrGRScQUa6S
4cAxTpxYmEic+X3l2RxGGz5TxmtQY72MVpGS
-----END PUBLIC KEY-----
generate classmethod
generate(curve_name: EllipticCurveName) -> EllipticCurveKeyPair

Generate an elliptic curve cryptographic key pair.

Parameters:
Returns:

EllipticCurveName

Bases: Enum

Elliptic Curve Names

EllipticCurvePrivateKey

Bases: CryptoPrivateKey

Represents an elliptic curve cryptographic private key.

from_cryptography classmethod
from_cryptography(key: ec.EllipticCurvePrivateKey) -> EllipticCurvePrivateKey

Create an EllipticCurvePrivateKey from a cryptography private key.

Parameters:
Returns:

EllipticCurvePublicKey

Bases: CryptoPublicKey

Represents an elliptic curve cryptographic public key.

ocsp_bytes property
ocsp_bytes: bytes

The bytes used for the OCSP Response hash

Returns:
  • bytes( bytes ) –

    The bytes used for the OCSP Response hash

from_cryptography classmethod
from_cryptography(key: ec.EllipticCurvePublicKey) -> EllipticCurvePublicKey

Create an EllipticCurvePublicKey from a cryptography public key.

Parameters:
Returns:

RSAKeyPair

Bases: CryptoKeyPair

Describes an RSA Key Pair including the public and private RSA keys.

Examples
Generate keypair
from pki_tools import RSAKeyPair

key_pair = RSAKeyPair.generate()

print(key_pair.private_key.pem_string)
print(key_pair.public_key.pem_string)
Print output
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA3/BWC4F4xtU+dSJ2oGbibuA8CWLNUJ13Y6ZjsYBE8eJyJklU
F2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9b+Zn1QWr78Lb5vlRAXSJzIF5JoDr
DdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72OrG02C2Yw6+odAwJ+mcKHgqpAv3ERP
Z5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZMfdbSpGAY43gOQ9Apk+VsmB98Ws2K
Nq2S79aYw8SpRwDaZ1/c4pq24Py8TmSyvDKF4gRcAh1FC00tZXlBLiO+XP2gy1Vc
p3RR6ec/X5htYEnKI8eY3XXqRTNmrELOyvKDXwIDAQABAoIBAFwisgRB3MNR8USY
TV5pdjhQIeNqtza30us5BkN9luA+XuDJwsNvkAT+6JMj6FYYngcwEEVrW6qYjI3z
GD9o5BgqIAZRMxCOh5NceKu0mw19J69j01H6cNPC/kYhKB2/MQJL/DKE71wtrGl9
jQSFaVzuYyvGum1hQI8AIKaus5T4wLjawIfoKAHwt3T5JP3bHbifiTOordw+n3/z
B1ZnYAkot1ySz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qhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3/BWC4F4xtU+dSJ2oGbi
buA8CWLNUJ13Y6ZjsYBE8eJyJklUF2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9
b+Zn1QWr78Lb5vlRAXSJzIF5JoDrDdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72Or
G02C2Yw6+odAwJ+mcKHgqpAv3ERPZ5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZM
fdbSpGAY43gOQ9Apk+VsmB98Ws2KNq2S79aYw8SpRwDaZ1/c4pq24Py8TmSyvDKF
4gRcAh1FC00tZXlBLiO+XP2gy1Vcp3RR6ec/X5htYEnKI8eY3XXqRTNmrELOyvKD
XwIDAQAB
-----END PUBLIC KEY-----

InitCryptoParser.from_cryptography
crypto_keys
from cryptography.hazmat.primitives import serialization

private_key_pem = b"""
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA3/BWC4F4xtU+dSJ2oGbibuA8CWLNUJ13Y6ZjsYBE8eJyJklU
F2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9b+Zn1QWr78Lb5vlRAXSJzIF5JoDr
DdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72OrG02C2Yw6+odAwJ+mcKHgqpAv3ERP
Z5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZMfdbSpGAY43gOQ9Apk+VsmB98Ws2K
Nq2S79aYw8SpRwDaZ1/c4pq24Py8TmSyvDKF4gRcAh1FC00tZXlBLiO+XP2gy1Vc
p3RR6ec/X5htYEnKI8eY3XXqRTNmrELOyvKDXwIDAQABAoIBAFwisgRB3MNR8USY
TV5pdjhQIeNqtza30us5BkN9luA+XuDJwsNvkAT+6JMj6FYYngcwEEVrW6qYjI3z
GD9o5BgqIAZRMxCOh5NceKu0mw19J69j01H6cNPC/kYhKB2/MQJL/DKE71wtrGl9
jQSFaVzuYyvGum1hQI8AIKaus5T4wLjawIfoKAHwt3T5JP3bHbifi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_pem = b"""
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3/BWC4F4xtU+dSJ2oGbi
buA8CWLNUJ13Y6ZjsYBE8eJyJklUF2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9
b+Zn1QWr78Lb5vlRAXSJzIF5JoDrDdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72Or
G02C2Yw6+odAwJ+mcKHgqpAv3ERPZ5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZM
fdbSpGAY43gOQ9Apk+VsmB98Ws2KNq2S79aYw8SpRwDaZ1/c4pq24Py8TmSyvDKF
4gRcAh1FC00tZXlBLiO+XP2gy1Vcp3RR6ec/X5htYEnKI8eY3XXqRTNmrELOyvKD
XwIDAQAB
-----END PUBLIC KEY-----
"""

crypto_public_key = serialization.load_pem_public_key(public_key_pem)
crypto_private_key = serialization.load_pem_private_key(
    private_key_pem, password=None
)
from pki_tools import RSAKeyPair, RSAPublicKey, RSAPrivateKey

key_pair = RSAKeyPair(
    public_key=RSAPublicKey.from_cryptography(crypto_public_key),
    private_key=RSAPrivateKey.from_cryptography(crypto_private_key),
)

print(key_pair)
Print output
RSAKeyPair:
  dmp1: '112228686098578289968206530398533832532087447182265458927579178422537594762937437642180841888657547745928845047872078923698573703206852833875325942746947034409646092798142300954781253256688565019637511208816685001820432660240910353920670244495107288979659625476528077796586331820727653559440906169349663093669'
  dmq1: '29954878721454193261115798178826603818564585216011358474569809730587326380303847036263030712995464073115054903542089837665013809425951577679466246151951773611972881297374240238476709888387164594515787280324519624175913491034621711981569648269575792417502609736379495957362666551513872949291463489602901607213'
  iqmp: '113377739742320119075874747148659403125690780467991563336450504742031829267730903383652084524673224369283355331374717321716590128967084240861243830597409710918961110635224262440163815022166491483352235666413036113542326814623174124611744543083546867929277477340240796140818812558974821133824541207302920805236'
  key_size: '2048'
  modulus_n: '28269656161865858123598576035899875440122191213127364861509154025675355610082799347921618153416712864686169355750843304814668229249598039750263836357726360127321991959996391367551966285361434131739675397279349625052844820155099922051021052083407166079301922726938201362153520404989534743429708886900189879132341366465692866810432101374364468049365637897193476795370556936116855076384721475999879171937784754794982370604637315116047432437846177894536884658616747452048948621460614753796193156319447575695952338495057296511722488852144978958149957659056926325939653530635680524483195710921326970123267059095715678683999'
  prime_p: '176343988128282274560558905337666014113390755615913385162357203871534832961198562678453231553308631389506790330681446124875528657773322644361822060222174297971780095032531395566268646927128401200987402529243546595802001852219150348004003112361261272096189140829442581566445573582081282968306089036435034888629'
  prime_q: '160309724544173073963232571063674598600136144153334672574545289916176842151394187752373856266338700715314498874198754016907725790327338604146593122167276121771016390787687047403972573571388992816493642903040016544962995464799608291534879147365930810686417486060191329949181535014418152170318033865597367518531'
  private_exponent_d: '11631032985161832223701298567709908011771285897596262662705537774818961634958460131183278329626443775018659238422047681020228483657875117015214521316961923409266676704904751466113359154652878678124244433102528087796586778928881613412022699366418829457593375412502275989580046755270119395484057409194450766756418131355912574189524935045679200576802226542785707366549488966278026499105874223053296922290636700877634060131880477412241318572951128535689940811404135636039231063146125793446617452698102772766197719549943252614774826460673259451470604957009429087881450367160663455331454289837597840202113495148183100561953'
  public_exponent_e: '65537'

InitCryptoParser.from_file
private.pem
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA3/BWC4F4xtU+dSJ2oGbibuA8CWLNUJ13Y6ZjsYBE8eJyJklU
F2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9b+Zn1QWr78Lb5vlRAXSJzIF5JoDr
DdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72OrG02C2Yw6+odAwJ+mcKHgqpAv3ERP
Z5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZMfdbSpGAY43gOQ9Apk+VsmB98Ws2K
Nq2S79aYw8SpRwDaZ1/c4pq24Py8TmSyvDKF4gRcAh1FC00tZXlBLiO+XP2gy1Vc
p3RR6ec/X5htYEnKI8eY3XXqRTNmrELO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WDLQKBgQChdIv3B9cxyU2yGpET3/bxdLIInhJQ6vi2vGtlaIsuzPEMgxRyJZG3
TNgNLW052w0tnMGq4BWjZM2GpONwDwHzWyqVMrWXzdzU6XJTQRKxQZg4p/QVZBW0
8iQGzFv2pa+taKWUXM16eYVcs4MuRoigvosKRJNGLlJAIRB7qHEbdA==
-----END RSA PRIVATE KEY-----
public.pem
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3/BWC4F4xtU+dSJ2oGbi
buA8CWLNUJ13Y6ZjsYBE8eJyJklUF2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9
b+Zn1QWr78Lb5vlRAXSJzIF5JoDrDdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72Or
G02C2Yw6+odAwJ+mcKHgqpAv3ERPZ5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZM
fdbSpGAY43gOQ9Apk+VsmB98Ws2KNq2S79aYw8SpRwDaZ1/c4pq24Py8TmSyvDKF
4gRcAh1FC00tZXlBLiO+XP2gy1Vcp3RR6ec/X5htYEnKI8eY3XXqRTNmrELOyvKD
XwIDAQAB
-----END PUBLIC KEY-----
from pki_tools import RSAKeyPair, RSAPublicKey, RSAPrivateKey

key_pair = RSAKeyPair(
    public_key=RSAPublicKey.from_file("public.pem"),
    private_key=RSAPrivateKey.from_file("private.pem"),
)

print(key_pair)
Print output
RSAKeyPair:
  dmp1: '112228686098578289968206530398533832532087447182265458927579178422537594762937437642180841888657547745928845047872078923698573703206852833875325942746947034409646092798142300954781253256688565019637511208816685001820432660240910353920670244495107288979659625476528077796586331820727653559440906169349663093669'
  dmq1: '29954878721454193261115798178826603818564585216011358474569809730587326380303847036263030712995464073115054903542089837665013809425951577679466246151951773611972881297374240238476709888387164594515787280324519624175913491034621711981569648269575792417502609736379495957362666551513872949291463489602901607213'
  iqmp: '113377739742320119075874747148659403125690780467991563336450504742031829267730903383652084524673224369283355331374717321716590128967084240861243830597409710918961110635224262440163815022166491483352235666413036113542326814623174124611744543083546867929277477340240796140818812558974821133824541207302920805236'
  key_size: '2048'
  modulus_n: '28269656161865858123598576035899875440122191213127364861509154025675355610082799347921618153416712864686169355750843304814668229249598039750263836357726360127321991959996391367551966285361434131739675397279349625052844820155099922051021052083407166079301922726938201362153520404989534743429708886900189879132341366465692866810432101374364468049365637897193476795370556936116855076384721475999879171937784754794982370604637315116047432437846177894536884658616747452048948621460614753796193156319447575695952338495057296511722488852144978958149957659056926325939653530635680524483195710921326970123267059095715678683999'
  prime_p: '176343988128282274560558905337666014113390755615913385162357203871534832961198562678453231553308631389506790330681446124875528657773322644361822060222174297971780095032531395566268646927128401200987402529243546595802001852219150348004003112361261272096189140829442581566445573582081282968306089036435034888629'
  prime_q: '160309724544173073963232571063674598600136144153334672574545289916176842151394187752373856266338700715314498874198754016907725790327338604146593122167276121771016390787687047403972573571388992816493642903040016544962995464799608291534879147365930810686417486060191329949181535014418152170318033865597367518531'
  private_exponent_d: '11631032985161832223701298567709908011771285897596262662705537774818961634958460131183278329626443775018659238422047681020228483657875117015214521316961923409266676704904751466113359154652878678124244433102528087796586778928881613412022699366418829457593375412502275989580046755270119395484057409194450766756418131355912574189524935045679200576802226542785707366549488966278026499105874223053296922290636700877634060131880477412241318572951128535689940811404135636039231063146125793446617452698102772766197719549943252614774826460673259451470604957009429087881450367160663455331454289837597840202113495148183100561953'
  public_exponent_e: '65537'

InitCryptoParser.from_pem_string
private_pem
private_pem = """
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA3/BWC4F4xtU+dSJ2oGbibuA8CWLNUJ13Y6ZjsYBE8eJyJklU
F2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9b+Zn1QWr78Lb5vlRAXSJzIF5JoDr
DdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72OrG02C2Yw6+odAwJ+mcKHgqpAv3ERP
Z5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZMfd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3ySYX8EU24qlAhUYKijTqgH3k4VrmVYogwMxvMyfzMT4G4bvyJbxbKOTe1+
WEkiuNkKtSX/0zpza5/eHlbiCxmpce19efrqrfc8wnMPjwmd4hgaUp1Zg5U4C3Xd
L9WDLQKBgQChdIv3B9cxyU2yGpET3/bxdLIInhJQ6vi2vGtlaIsuzPEMgxRyJZG3
TNgNLW052w0tnMGq4BWjZM2GpONwDwHzWyqVMrWXzdzU6XJTQRKxQZg4p/QVZBW0
8iQGzFv2pa+taKWUXM16eYVcs4MuRoigvosKRJNGLlJAIRB7qHEbdA==
-----END RSA PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3/BWC4F4xtU+dSJ2oGbi
buA8CWLNUJ13Y6ZjsYBE8eJyJklUF2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9
b+Zn1QWr78Lb5vlRAXSJzIF5JoDrDdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72Or
G02C2Yw6+odAwJ+mcKHgqpAv3ERPZ5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZM
fdbSpGAY43gOQ9Apk+VsmB98Ws2KNq2S79aYw8SpRwDaZ1/c4pq24Py8TmSyvDKF
4gRcAh1FC00tZXlBLiO+XP2gy1Vcp3RR6ec/X5htYEnKI8eY3XXqRTNmrELOyvKD
XwIDAQAB
-----END PUBLIC KEY-----
"""
from pki_tools import RSAKeyPair, RSAPublicKey, RSAPrivateKey

key_pair = RSAKeyPair(
    public_key=RSAPublicKey.from_pem_string(public_pem),
    private_key=RSAPrivateKey.from_pem_string(private_pem),
)

print(key_pair)
Print output
RSAKeyPair:
  dmp1: '112228686098578289968206530398533832532087447182265458927579178422537594762937437642180841888657547745928845047872078923698573703206852833875325942746947034409646092798142300954781253256688565019637511208816685001820432660240910353920670244495107288979659625476528077796586331820727653559440906169349663093669'
  dmq1: '29954878721454193261115798178826603818564585216011358474569809730587326380303847036263030712995464073115054903542089837665013809425951577679466246151951773611972881297374240238476709888387164594515787280324519624175913491034621711981569648269575792417502609736379495957362666551513872949291463489602901607213'
  iqmp: '113377739742320119075874747148659403125690780467991563336450504742031829267730903383652084524673224369283355331374717321716590128967084240861243830597409710918961110635224262440163815022166491483352235666413036113542326814623174124611744543083546867929277477340240796140818812558974821133824541207302920805236'
  key_size: '2048'
  modulus_n: '28269656161865858123598576035899875440122191213127364861509154025675355610082799347921618153416712864686169355750843304814668229249598039750263836357726360127321991959996391367551966285361434131739675397279349625052844820155099922051021052083407166079301922726938201362153520404989534743429708886900189879132341366465692866810432101374364468049365637897193476795370556936116855076384721475999879171937784754794982370604637315116047432437846177894536884658616747452048948621460614753796193156319447575695952338495057296511722488852144978958149957659056926325939653530635680524483195710921326970123267059095715678683999'
  prime_p: '176343988128282274560558905337666014113390755615913385162357203871534832961198562678453231553308631389506790330681446124875528657773322644361822060222174297971780095032531395566268646927128401200987402529243546595802001852219150348004003112361261272096189140829442581566445573582081282968306089036435034888629'
  prime_q: '160309724544173073963232571063674598600136144153334672574545289916176842151394187752373856266338700715314498874198754016907725790327338604146593122167276121771016390787687047403972573571388992816493642903040016544962995464799608291534879147365930810686417486060191329949181535014418152170318033865597367518531'
  private_exponent_d: '11631032985161832223701298567709908011771285897596262662705537774818961634958460131183278329626443775018659238422047681020228483657875117015214521316961923409266676704904751466113359154652878678124244433102528087796586778928881613412022699366418829457593375412502275989580046755270119395484057409194450766756418131355912574189524935045679200576802226542785707366549488966278026499105874223053296922290636700877634060131880477412241318572951128535689940811404135636039231063146125793446617452698102772766197719549943252614774826460673259451470604957009429087881450367160663455331454289837597840202113495148183100561953'
  public_exponent_e: '65537'

InitCryptoParser.to_file
private_pem
private_pem = """
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA3/BWC4F4xtU+dSJ2oGbibuA8CWLNUJ13Y6ZjsYBE8eJyJklU
F2pnuCNe/7NldFTNhv0SF0avR8caYSQ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8SRCU
qRO4XKSbjL6427h0vyQ7rU8zb4wxaf1Nf2sEojvGWJVX4vhfDMjHQxzrBa26dMyU
d2k6KjqQc053jYIoD0lD86UCgYAqqDvZyiiJKPS6/dPED0or5UzW3bXIN1Y3i4dJ
N7bMN3ySYX8EU24qlAhUYKijTqgH3k4VrmVYogwMxvMyfzMT4G4bvyJbxbKOTe1+
WEkiuNkKtSX/0zpza5/eHlbiCxmpce19efrqrfc8wnMPjwmd4hgaUp1Zg5U4C3Xd
L9WDLQKBgQChdIv3B9cxyU2yGpET3/bxdLIInhJQ6vi2vGtlaIsuzPEMgxRyJZG3
TNgNLW052w0tnMGq4BWjZM2GpONwDwHzWyqVMrWXzdzU6XJTQRKxQZg4p/QVZBW0
8iQGzFv2pa+taKWUXM16eYVcs4MuRoigvosKRJNGLlJAIRB7qHEbdA==
-----END RSA PRIVATE KEY-----
"""
public_pem
public_pem = """
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3/BWC4F4xtU+dSJ2oGbi
buA8CWLNUJ13Y6ZjsYBE8eJyJklUF2pnuCNe/7NldFTNhv0SF0avR8caYSQFy9S9
b+Zn1QWr78Lb5vlRAXSJzIF5JoDrDdcWgMbdVosNsvoaEOi0wRVmDbgnaWdR72Or
G02C2Yw6+odAwJ+mcKHgqpAv3ERPZ5mOWdQEm2ibdDIl4q9HOdnMokxbGsB5GqZM
fdbSpGAY43gOQ9Apk+VsmB98Ws2KNq2S79aYw8SpRwDaZ1/c4pq24Py8TmSyvDKF
4gRcAh1FC00tZXlBLiO+XP2gy1Vcp3RR6ec/X5htYEnKI8eY3XXqRTNmrELOyvKD
XwIDAQAB
-----END PUBLIC KEY-----
"""
from pki_tools import RSAKeyPair, RSAPublicKey, RSAPrivateKey

key_pair = RSAKeyPair(
    public_key=RSAPublicKey.from_pem_string(public_pem),
    private_key=RSAPrivateKey.from_pem_string(private_pem),
)

key_pair.public_key.to_file("out_public.pem")
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EY-----
generate classmethod
generate(key_size: int = 2048, exponent: int = 65537) -> RSAKeyPair

Generate an RSA cryptographic key pair.

Parameters:
  • key_size (int, default: 2048 ) –

    The size of the key. Defaults to 2048.

  • exponent (int, default: 65537 ) –

    The public exponent. Defaults to 65537.

Returns:

RSAPrivateKey

Bases: CryptoPrivateKey

Represents an RSA cryptographic key pair.

from_cryptography classmethod
from_cryptography(key: rsa.RSAPrivateKey) -> RSAPrivateKey

Create an RSA private key from a cryptography key.

Parameters:
Returns:

RSAPublicKey

Bases: CryptoPublicKey

Represents an RSA cryptographic key pair.

der_bytes property
der_bytes: bytes

Property to get the DER encoding of the public key.

Returns:
  • bytes( bytes ) –

    The DER encoded public key.

from_cryptography classmethod
from_cryptography(key: rsa.RSAPublicKey) -> RSAPublicKey

Create an RSA public key from a cryptography public key.

Parameters:
Returns: