Encoding with RSA public key and decoding with private key
See original GitHub issueIn 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:
- Created 9 years ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Closed via #88