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.

Exception during sign. 'SHA512' object has no attribute 'oid'

See original GitHub issue

I created a key pair like so:

> openssl genrsa -out key.pem 4096
> openssl rsa -in key.pem -pubout -out pubkey.pem

Then in the python REPL:

>>> from jwt.contrib.algorithms.pycrypto import RSAAlgorithm
>>> import jwt
>>> jwt.register_algorithm('RS512', RSAAlgorithm(RSAAlgorithm.SHA512))
>>> with open('.keys/key.pem') as fo: private_key_bytes = fo.read()
...
>>> result = jwt.encode({'name':'John'}, private_key_bytes, algorithm='RS512')

This raises an exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.10-intel/egg/jwt/api.py", line 103, in encode
  File "build/bdist.macosx-10.10-intel/egg/jwt/contrib/algorithms/pycrypto.py", line 44, in sign
  File "site-packages/Crypto/Signature/PKCS1_v1_5.py", line 110, in sign
    em = EMSA_PKCS1_V1_5_ENCODE(mhash, k)
  File "site-packages/Crypto/Signature/PKCS1_v1_5.py", line 211, in EMSA_PKCS1_V1_5_ENCODE
    digestAlgo  = DerSequence([hash.oid, DerNull().encode()])
AttributeError: 'SHA512' object has no attribute 'oid'

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
johnlockwood-wfcommented, Mar 27, 2015

PyCrypto just seems to be building badly in this virtualenv, so I’m going to close this. Thanks

0reactions
johnlockwood-wfcommented, Mar 27, 2015

I used pip installs instead of installing from cloned git repos.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'NoneType' object has no attribute 'oid' while using ...
python - PyCrypto: Attribute Error: 'NoneType' object has no attribute 'oid' while using PKCS1_v1_5 - Stack Overflow. Stack Overflow for Teams ...
Read more >
X.509 Reference — Cryptography 39.0.0.dev1 documentation
Returns the HashAlgorithm which was used in signing this certificate. Can be None if signature did not use separate hash ( ED25519 ,...
Read more >
PyCryptodome Documentation - Read the Docs
A CBC cipher object has a read-only attribute iv, holding the Initialization Vector (bytes). Example (encryption):. >>> import json.
Read more >
Bug #502291 “Support for PKCS#1 v1.5 signatures (RFC3447)”
This patch adds support for PKCS#1 v1.5 signatures. The sign() and verify() methods for an RSA key object are extended to accept an...
Read more >
Changelog — PyCryptodome 3.11.0 documentation
Padding.unpad() was raising an incorrect exception in case of ... New attribute oid for Hash objects with ASN.1 Object ID; Added Crypto.
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