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.
.Replace("\\n", "\\n")<-- This won't do anything useful, is this a typo?...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 ('=').