0

I am working on Snowflake Database Key-Pair implementation (migrating from user_id & password to Key-Pair) in .net Framework 4.8. I have installed Snowflake data connector version 4.0. I have encrypted private key and its passphrase. When I am trying to implement the connection using private key and its passphrase, I am getting

Snowflake.Data.Client.SnowflakeDbException: 'Error: Could not read private key with value passed in connection string. \n Error : incorrect private key value or private key format: use "\n" for newlines and double the equals sign.

I don't have (=) sign in private key.

I also implemented

string privateKeyContent = File.ReadAllText("path_to_private_key_file").Replace("\\n", "\\n").Replace("=", "==");

to avoid any human mistakes but still getting the error.

Here is the dummy code i am trying to connect to Snowflake Database.

static void Main(string[] args) 
{
 string keyText = File.ReadAllText(@"C:\CARAT\Snowflake_program\Private_key.txt").Replace("\n", "\\n").Replace("=", "=="); 
 string keyPwd = Environment.GetEnvironmentVariable(<My_Passpharse>);
 SnowflakeDbConnectionStringBuilder connStringBuilder = new SnowflakeDbConnectionStringBuilder()
 {
 ["ACCOUNT"] = "<MY ACCOUNT_NAME>",
 ["DB"] = "<MY DB_NAME>",
 ["SCHEMA"] = "<MY SCEHMA_NAME>",
 ["USER"] = "<MY USER_NAME>",
 ["ROLE"] = "<MY ROLE_NAME>",
 ["WAREHOUSE"] = "<MY WH_NAME>",
 ["AUTHENTICATOR"] = "SNOWFLAKE_JWT",
 ["PRIVATE_KEY"] = keyText,
 ["PRIVATE_KEY_PWD"] = keyPwd,
 };
 SnowflakeDbConnection conn = new SnowflakeDbConnection();
 conn.ConnectionString = connStringBuilder.ConnectionString;
 conn.Open();
 Console.WriteLine("Connection successful!");
} 

While Opening the connection getting unable to read private key error.

samhita
4,2512 gold badges12 silver badges19 bronze badges
asked Nov 14, 2024 at 14:05
3
  • 2
    .Replace("\\n", "\\n") <-- This won't do anything useful, is this a typo? Commented Nov 14, 2024 at 14:08
  • I don't understand why the error message suggests ...and double the equals sign..., that doesn't really make any sense. Base64 encoders either don't do any padding at all or they pad with the correct number of equal signs ('='). Commented Nov 14, 2024 at 15:25
  • yes exactly. Now i am passing the encrypted private key via bouncy castle library which decrypts the private key using passphrase and providing that private key in the SF connection string as parameter. still getting the above error while trying to open the connection. Getting error "PemException: problem creating ENCRYPTED private key: System.NullReferenceException: Object reference not set to an instance of an object. at Org.BouncyCastle.OpenSsl.PemReader.ReadPrivateKey(PemObject pemObject)" Dotnet framework - 4.8 Snowflake data connector - 4.0/4.2 Commented Nov 15, 2024 at 11:23

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.