Search code examples
pythonssl-certificatedersnowflake-cloud-data-platform

Convert Private key(string) to DER format using python


I am trying to do client authentication using ssl certificate. I got the private key ( as string ) from keyvault.

As part of the requirement, i need to convert the private key(generated using openssl command) to DER format for snowflake access.

private_key="MIIEpQIBAAKC .... "  #long string containing private key

pkb=<Above key in DER format> 

ctx = snowflake.connector.connect(
    user='SNOWFLAKE_USER',
    account='ACCOUNT',
    private_key=pkb,
    warehouse="WH",
    database="STG",
    schema="RAW"
    )

cs = ctx.cursor()```

Question: How to convert the private key string to DER format in python.

Solution

  • Take a look at the python docs, specifically the ssl library should be helpful:

    https://docs.python.org/3/library/ssl.html#ssl.PEM_cert_to_DER_cert