title: python cryptography fails to read snowflake private key in windows
body: <p>I am implementing a Snowflake connector using snowflake python driver. This is my code:</p>
  <pre><code>class SnowflakeDriver:
      def __init__(
          self,
          sf_user: str = os.environ[&quot;SNOWFLAKE_USERNAME&quot;],
          sf_account: str = os.environ[&quot;SNOWFLAKE_ACCOUNT&quot;],
          sf_private_key: str = os.environ[&quot;SNOWFLAKE_PRIVATE_KEY&quot;],
          sf_role: str = os.environ[&quot;SNOWFLAKE_ROLE&quot;],
          private_key_isa_file: bool = False,
          sf_warehouse: str = os.environ[&quot;SNOWFLAKE_WAREHOUSE&quot;],
          sf_database: str = os.environ[&quot;SNOWFLAKE_DATABASE&quot;],
      ):
  
          try:
              if private_key_isa_file:
                  with open(sf_private_key, &quot;r&quot;, encoding=&quot;utf-8&quot;) as file:
                      key = file.read()
              else:
                  key = sf_private_key
          except FileNotFoundError as err:
              print(f&quot;{err}&quot;)
              sys.exit(1)
  
          private_key_serialized = serialization.load_pem_private_key(sf_private_key.encode(), password=None, backend=default_backend())
          private_key_encrypted = private_key_serialized.private_bytes(
              encoding=serialization.Encoding.DER,
              format=serialization.PrivateFormat.PKCS8,
              encryption_algorithm=serialization.NoEncryption()
                  )
          try:
              conn = snowflake.connector.connect(
                  user=sf_user,
                  account=sf_account,
                  private_key=private_key_encrypted,
                  warehouse=sf_warehouse,
                  database=sf_database,
                  role=sf_role
                  )
              cs = conn.cursor()
              try:
                  cs.execute(&quot;SELECT current_version()&quot;)
                  one_row = cs.fetchone()
                  print(one_row[0])
              finally:
                  cs.close()
              conn.close()
  
          except OperationalError as err:
              print(f&quot;{err}&quot;)
              sys.exit(1)
  
          self.conn = conn
  
      def execute_query(self, query: str):
          cursor = self.conn.cursor()
          cursor.execute(query)
          rw_ct = cursor.rowcount
          self.conn.commit()
  
          return rw_ct
  </code></pre>
  <p>The problem is that I'm getting the following error:</p>
  <pre><code>ValueError: ('Could not deserialize key data. The data may be in an incorrect format, it may be encrypted with an unsupported algorithm, or it may be an unsupported key type (e.g. EC curves with explicit parameters).', [_OpenSSLErrorWithText(code=151584876, lib=9, reason=108, reason_text=b'error:0909006C:PEM routines:get_name:no start line')])
  </code></pre>
  <p>The sentence that raises the exception is <code>private_key_serialized = serialization.load_pem_private_key(sf_private_key.encode(), password=None, backend=default_backend())</code></p>
  <p>This seems to happen only in Windows and work in linux, so I think It might be the way secret keys are stored as environment variables.</p>