Publickey¶
- class chepy.modules.publickey.Publickey(*data)¶
- der_hex_to_pem() PublickeyT ¶
Convert DER format to PEM cert.
Converts a hexadecimal DER (Distinguished Encoding Rules) string into PEM (Privacy Enhanced Mail) format.
- Returns
The Chepy object.
- Return type
Examples
>>> c = Chepy(str(Path().absolute() / "tests/files/test.der")) >>> c.load_file() >>> c.der_hex_to_pem() >>> c.o.decode() -----BEGIN CERTIFICATE----- MIICeTCCAeICCQDi5dgCpKMeHTANBgkqhkiG9w0BAQsFADCBgDELMAkGA1UEBhMC VVMxDDAKBgNVBAgMA2xvbDEMMAoGA1UEBwwDbnljMRIwEAYDVQQKDAlzZWN1cmlz ... wQSFm54UNQ/vjM12yZ+C5c3268Vo8jSP7mI5R3wn6XztjUSXkDg5/3IL3kojti/h nyhBHx2QCVke7BxWw3HWkbZ/1BKl0HnCGyd5HDTuOtlBmTS+QrJoNpdsn0zq4fvc igbV1IJdKTBAiZzaOQ== -----END CERTIFICATE-----
- dump_pkcs12_cert(password: str) PublickeyT ¶
Get the private key and cert from pkcs12 cert
- Parameters
password (str) – Password for certificate
- Returns
The Chepy object.
- Return type
- generate_ecc_keypair(curve: Literal['p256', 'p384', 'p521'] = 'p256', format: Literal['PEM', 'DER'] = 'PEM') PublickeyT ¶
Generate RSA key pair
- Parameters
curve (Literal[, optional) – Curve for keys. Defaults to p256.
format (Literal[, optional) – Output format type. Defaults to ‘PEM’.
- Returns
The Chepy object.
- Return type
- generate_rsa_keypair(bits: int = 1024, format: Literal['PEM', 'DER'] = 'PEM', passphrase: str = None) PublickeyT ¶
Generate RSA key pair
- Parameters
bits (int, optional) – Length of keys. Defaults to 1024.
format (Literal[, optional) – Output format type. Defaults to ‘PEM’.
passphrase (str, optional) – Passphrase for keys. Defaults to None.
- Returns
The Chepy object.
- Return type
- parse_public_pem() PublickeyT ¶
Parse pubkey PEM to get n and e
- Returns
The Chepy object.
- Return type
Examples
>>> Chepy("tests/files/public.pem").load_file().parse_public_pem().get_by_key("e").o 65537
- parse_x509_der_hex() PublickeyT ¶
Parse X509 cert in DER format
X.509 is an ITU-T standard for a public key infrastructure (PKI) and Privilege Management Infrastructure (PMI). It is commonly involved with SSL/TLS security.<br><br>This operation displays the contents of a certificate in a human readable format, similar to the openssl command line tool.
- Returns
A Chepy object.
- Return type
- parse_x509_pem() PublickeyT ¶
Parse X509 cert in PEM format
X.509 is an ITU-T standard for a public key infrastructure (PKI) and Privilege Management Infrastructure (PMI). It is commonly involved with SSL/TLS security. This operation displays the contents of a certificate in a human readable format, similar to the openssl command line tool.
- Returns
A Chepy object.
- Return type
Examples
>>> Chepy(path).load_file().parse_x509_pem().o { "version": 0, ... "after": b"20201101152508Z", "issuer": { "C": "US", ... "email": "none@email.com", }, "subject": { "C": "US", ... "email": "none@email.com", }, "pubkey": {"bits": 1024}, }
- pem_to_der_hex() PublickeyT ¶
Convert PEM cert to DER format
Converts PEM (Privacy Enhanced Mail) format to a hexadecimal DER (Distinguished Encoding Rules) string.
- Returns
The Chepy object.
- Return type