INNER CODE UNIT · Python

convert_to_pkcs12

ahembree/ansible-hms-docker · roles/hmsdocker/files/scripts/traefik_cert_convert.py:45

def convert_to_pkcs12(filename: str, pub: str, priv: str, priv_passphrase: str=None) -> None:
    """Converts PEM data into PKCS12 format and outputs to a file

    Args:
        filename (``str``): The path to the output file
        pub (``str``): The public certificate data
        priv (``str``): The certificate private key data
        priv_passphrase (``str``, optional): The private key passphrase. Defaults to ``None``.
    """    
    logging.debug(f'Converting to PKCS12 and outputting file to {filename}')
    cert = x509.load_pem_x509_certificate(str.encode(pub))
    if priv_passphrase is not None:
        key = load_pem_private_key(str.encode(priv), str.encode(priv_passphrase))
        p12 = pkcs12.serialize_key_and_certificates(None, key, cert, None, BestAvailableEncryption(str.encode(priv_passphrase)))
    else:
        key = load_pem_private_key(str.encode(priv), None)
        p12 = pkcs12.serialize_key_and_certificates(None, key, cert, None, NoEncryption())
    try:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…