title: ValueError: Could not deserialize key data during jwt encoding
body: <p>I am trying to generate a token using jwt and I'm passing the payload, secret_key, and algorithm ('RS256'). Here is the section of the code </p>
  
  <pre><code>secret_key = AppConfig.JWT_SECRET_KEY
  public_key = AppConfig.JWT_PUBLIC_KEY
  payload = {'UserInfo': user_one.to_dict()}
  payload['UserInfo']['picture'] = 'https://someimage.url'
  payload.__setitem__('exp', exp) if exp is not None else ''
  token = jwt.encode(payload, secret_key, algorithm='RS256').decode(CHARSET)
  </code></pre>
  
  <p>I'm getting this error </p>
  
  <pre><code>  File "/root/.pyenv/versions/3.6.5/lib/python3.6/code.py", line 91, in runcode
      exec(code, self.locals)
    File "&lt;console&gt;", line 1, in &lt;module&gt;
    File "/activo-api/tests/helpers/generate_token.py", line 30, in generate_token
      token = jwt.encode(payload, secret_key, algorithm='RS256').decode(CHARSET)
    File "/root/.local/share/virtualenvs/activo-api-lpKgDXk8/lib/python3.6/site-packages/jwt/api_jwt.py", line 65, in encode
      json_payload, key, algorithm, headers, json_encoder
    File "/root/.local/share/virtualenvs/activo-api-lpKgDXk8/lib/python3.6/site-packages/jwt/api_jws.py", line 113, in encode
      key = alg_obj.prepare_key(key)
    File "/root/.local/share/virtualenvs/activo-api-lpKgDXk8/lib/python3.6/site-packages/jwt/algorithms.py", line 207, in prepare_key
      key = load_pem_public_key(key, backend=default_backend())
    File "/root/.local/share/virtualenvs/activo-api-lpKgDXk8/lib/python3.6/site-packages/cryptography/hazmat/primitives/serialization/base.py", line 20, in load_pem_public_key
      return backend.load_pem_public_key(data)
    File "/root/.local/share/virtualenvs/activo-api-lpKgDXk8/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1071, in load_pem_public_key
      self._handle_key_loading_error()
    File "/root/.local/share/virtualenvs/activo-api-lpKgDXk8/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1329, in _handle_key_loading_error
      raise ValueError("Could not deserialize key data.")
  ValueError: Could not deserialize key data.
  </code></pre>
  
  <p>When I use <code>HS256 algorithm</code>, a token is generated, but when I use <code>RS256 algorithm</code>, I get the error above. I have tried almost all the solutions provided online but I'm still getting the same error. </p>
  
  <p>My secret key has this format:</p>
  
  <pre><code>-----BEGIN RSA PRIVATE KEY-----
  MIIEpQIBAAKCAQEA3Tz2mr7SZiAMfQyuvBjM9Oi
  RK+Lh9x5eJPo5CAZ3/ANBE0sTK0ZsDGMak2m1g7
  wnLe4nOb7/eEJbDPkk05ShhBrJGBKKxb8n104o/
  ...........
  5A13wiLitEO7nco2WfyYkQzaxCw0AwzlkVHiIyC
  DtkpjGHQzPF6vOe907y5NQLvVFGXUq/FIJZxB8d==
  -----END RSA PRIVATE KEY-----
  </code></pre>
  
  <p>The expected output should be a token </p>