Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Last active April 2, 2026 09:55
Show Gist options
  • Select an option

  • Save gitfvb/32e57f460e9bba18744d0c20fed5fa15 to your computer and use it in GitHub Desktop.

Select an option

Save gitfvb/32e57f460e9bba18744d0c20fed5fa15 to your computer and use it in GitHub Desktop.
Create a snowflake public/private key to use in a .net connection string

Easiest is via Linux subsystem on Windows, but there would also be a way in Windows

#!/bin/bash
PASSPHRASE='YourStrongPassphrase123!'

# 1. Generate encrypted RSA private key in PKCS#8 format (.p8)
openssl genpkey \
  -algorithm RSA \
  -pkeyopt rsa_keygen_bits:2048 \
  -aes-256-cbc \
  -pass pass:"$PASSPHRASE" \
  -out rsa_key.p8

# 2. Extract the public key
openssl rsa \
  -in rsa_key.p8 \
  -passin pass:"$PASSPHRASE" \
  -pubout \
  -out rsa_key.pub

# 3. Strip header/footer for Snowflake
grep -v "^-----" rsa_key.pub | tr -d '\n'

# Empty the password variable and remove recent session history
unset PASSPHRASE
history -c

Save the p8 (or show via cat rsa_key.p8), the public key and the passphrase securely and delete the files on the linux machine afterwards.

In Snowflake you need to attach the public key to a user like

ALTER USER myuser SET RSA_PUBLIC_KEY='MIIBIjANBgkq...your key content...';

And then you can use your snowflake connection string

account=myaccount;user=myuser;db=testdb;schema=abc;AUTHENTICATOR=snowflake_jwt;PRIVATE_KEY_FILE=C:\temp\rsa_key.p8;PRIVATE_KEY_PWD=YourStrongPassphrase123!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment