72
Views
4
Comments
[Snowflake Connector] RunQueryWithKeyPairAuthFilePath
Question
snowflake-connector
Service icon
Forge asset by Rita Tomé
Application Type
Service

Hi,

I am trying to connect to Snowflake using the RunQueryWithKeyPairAuthFilePath  action from the Snowflake forge component Version 1.1.0.

Im getting this error:

There was an error. 

 Message: Could not read private key X:\<filepath>\<key_filename>. \n Error : Org.BouncyCastle.OpenSsl.PemException: problem creating ENCRYPTED private key: Org.BouncyCastle.Crypto.InvalidCipherTextException: pad block corrupted

   at Org.BouncyCastle.Crypto.Paddings.Pkcs7Padding.PadCount(Byte[] input)

   at Org.BouncyCastle.Crypto.Paddings.PaddedBufferedBlockCipher.DoFinal(Byte[] output, Int32 outOff)

   at Org.BouncyCastle.Crypto.BufferedBlockCipher.DoFinal(Byte[] input, Int32 inOff, Int32 inLen)

   at Org.BouncyCastle.Pkcs.PrivateKeyInfoFactory.CreatePrivateKeyInfo(Char[] passPhrase, Boolean wrongPkcs12Zero, EncryptedPrivateKeyInfo encInfo)

   at Org.BouncyCastle.OpenSsl.PemReader.ReadPrivateKey(PemObject pemObject)

   at Org.BouncyCastle.OpenSsl.PemReader.ReadPrivateKey(PemObject pemObject)

   at Snowflake.Data.Core.Authenticator.KeyPairAuthenticator.GenerateJwtToken()

 Stacktrace:    at Snowflake.Data.Core.Authenticator.KeyPairAuthenticator.GenerateJwtToken()

   at Snowflake.Data.Core.Authenticator.KeyPairAuthenticator.Authenticate()

   at Snowflake.Data.Client.SnowflakeDbConnection.Open()

   at OutSystems.NssSnowflakeConnector.CssSnowflakeConnector.RunQuery(String ssQuery, Boolean& ssIsSuccessful, String& ssResultInJSON, SnowflakeDbConnection conn, String connectionString)

   at OutSystems.NssSnowflakeConnector.CssSnowflakeConnector.MssRunQueryWithKeyPairAuthFilePath(String ssAccount, String ssDatabase, String ssHost, String ssRole, String ssSchema, String ssUser, String ssWarehouse, String ssPrivateKeyFilepath, String ssPrivateKeyPassword, String ssExtraParametersForConnectionString, String ssQuery, Boolean& ssIsSuccessful, String& ssResultInJSON)

 Error Code: 270052

 Source: Snowflake.Data

 Data: System.Collections.ListDictionaryInternal

 InnerException:


I have placed the key file on the Outsystems frontend server and the snowflake connector is able to find this file. I tested this by changing the filename and then I get a different error:

There was an error. 

 Message: Snowflake Internal Error: Unable to connect. Could not find file 'X:\<filepath>\<incorrect_key_filename> '.

 Stacktrace:    at Snowflake.Data.Client.SnowflakeDbConnection.Open()


This points to an incorrect password and when I googled this "pad block corrupted" this also suggests an incorrect password. However Im sure the password is correct because I have succesfully created an ODBC connection to Snowflake on the Outsystems frontend server using the same key file and the same password I am passing in the RunQueryWithKeyPairAuthFilePath. The password consists only of letters, numbers and an exclemation mark:    AAbbb123! 

So Im a bit lost here. Any help would be greatly appreciated.

regards,

Leon



2025-04-17 05-42-16
Ajit Kurane

Hi Leon,

Looking at your issue it seems that you have tried hard to resolve it.

I am not sure about below document but hope so you will get some hints after go through it.

https://community.snowflake.com/s/question/0D50Z00009Urma1SAB/invalid-private-key-error-trying-to-connect-snowflake

Please let me know if it works for you.

Thanks,

Ajit Kurane.

2025-04-17 05-42-16
Ajit Kurane

Also I am attaching one file here for snowflake connector settings.

Please check it how the inputs are passed there and make changes accordingly at your side.


SnowflakeConnector.oap
2021-12-04 14-06-49
krishna_Wipro

Hi Leon,

Would like to know did u get solution for this issue?

Error message:

There was an error.
 Message: 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.
 Stacktrace:    at Snowflake.Data.Core.Authenticator.KeyPairAuthenticator.GenerateJwtToken()
   at Snowflake.Data.Core.Authenticator.KeyPairAuthenticator.Authenticate()
   at Snowflake.Data.Client.SnowflakeDbConnection.Open()
   at OutSystems.NssSnowflakeConnector.CssSnowflakeConnector.RunQuery(String ssQuery, Boolean& ssIsSuccessful, String& ssResultInJSON, SnowflakeDbConnection conn, String connectionString)
   at OutSystems.NssSnowflakeConnector.CssSnowflakeConnector.MssRunQueryWithKeyPairAuthContent(String ssAccount, String ssDatabase, String ssHost, String ssRole, String ssSchema, String ssUser, String ssWarehouse, String ssPrivateKeyContent, String ssExtraParametersForConnectionString, String ssQuery, Boolean& ssIsSuccessful, String& ssResultInJSON)
 Error Code: 270052
 Source: Snowflake.Data
 Data: System.Collections.ListDictionaryInternal
 InnerException: 

Thanks & Regards,

Krishna.

UserImage.jpg
Snb

Hi @krisha  


Did you get it working?

I am struggling with similar issue, but for me at least private key is being read by connector.

I have added following code in the .net extension before passing the private key content in the connection string

 ssPrivateKeyContent = ssPrivateKeyContent.Replace("\r\n", "\n");


Thanks,

Sapna



Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.