question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Encoding with RSA public key and decoding with private key

See original GitHub issue

In the documentation it says:

When using the RSASSA-PKCS1-v1_5 algorithms, the key argument in both jwt.encode() and jwt.decode() (“secret” in the examples) is expected to be either an RSA public or private key in PEM format.

When i try to encode the payload with the public key i get an error:

>>> jwt_message = jwt.encode(payload, pub_rsakey, 'RS384')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/sven/code/sso/env/lib/python2.7/site-packages/jwt/__init__.py",
 line 295, in encode
    signature = signing_methods[algorithm](signing_input, key)
  File "/Users/sven/code/sso/env/lib/python2.7/site-packages/jwt/__init__.py",
 line 131, in <lambda>
    'RS384': lambda msg, key: sign_rsa(msg, key, hashes.SHA384()),
  File "/Users/sven/code/sso/env/lib/python2.7/site-packages/jwt/__init__.py",
 line 106, in sign_rsa
    signer = key.signer(
AttributeError: '_RSAPublicKey' object has no attribute 'signer'

What is happening is that the implementation in algorithms.py, line 137 tries to sign with the public key, but the cryptography.hazmat.backends.openssl.rsa._RSAPublicKey has no signer method: https://cryptography.io/en/latest/hazmat/primitives/interfaces/#cryptography.hazmat.primitives.interfaces.RSAPublicKey

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
svnvcommented, Jan 22, 2015

So, it looks like I misunderstood how jwt works. I somehow thought that the payload was also encrypted with the RSA key. (I edited my previous post in light of my new knowledge.)

The documentation should at least be updated to reflect that encoding (signing) is only possible with a private RSA key and decoding (verification) only works with a public key.

0reactions
jpadillacommented, Jan 25, 2015

Closed via #88

Read more comments on GitHub >

github_iconTop Results From Across the Web

RSA encryption with private key and decryption with a public key
If message is encrypted with private key, then everyone can decrypt it, since the public key is public. The point of encryption is...
Read more >
Encrypt/Decrypt a file using RSA public-private key pair | what ...
Learn how to encrypt/decrypt a file with RSA public private key pair using OpenSSL commands.
Read more >
How public and private key encryption works - PreVeil
In public key cryptography, every public key matches to only one private key. Together, they are used to encrypt and decrypt messages.
Read more >
Decoding the RSA algorithm - Level Up Coding
The public keys are used to encrypt the data, and the private keys can decrypt the data, which means that only users that...
Read more >
Online RSA Encryption, Decryption And Key Generator Tool
Specify if the entered key is a public key or private key. As RSA is asymmetric encryption technique, if text is encrypted using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found