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.

RSAPublicKey is backwards in order of modulus and exponent

See original GitHub issue

OpenSSL doesn’t like the order you have the asn1crypto.keys.RSAPublicKey object. Simply switching the order around let’s things parse correctly. I overrode with my own class, like so:

`class MyRSAPublicKey(Sequence):

_fields = [
    ('public_exponent', Integer),
    ('modulus', Integer),
]`

Example parsing the RSAPublicKey with it currently:

openssl rsa -pubin -inform PEM -text -noout < test.pub Modulus (17 bit): 65537 (0x10001) Exponent: 00:c1:72:a6:ca:26:db:34:1e:8c:27:8d:d4:d6:0f: cd:05:16:55:95:a1:f0:a8:55:b4:a0:28:b1:db:bf: c5:df:f4:7b:b4:65:3f:31:5f:04:60:d8:d2:13:3a: 8a:58:93:78:68:a3:95:78:d8:72:0d:21:d5:f7:c3: a8:ae:7d:3a:ad:71:10:79:cf:8c:32:a3:95:16:92: 6d:63:1a:a3:55:e6:69:9a:37:0a:58:b6:44:dc:fe: be:39:12:d1:56:ef:15:99:8f:e4:ca:91:30:e8:e6: f5:fd:59:c5:17:61:53:b4:91:8d:df:53:8a:cc:b6: 4f:7b:c2:19:83:db:76:8b:44:55:85🇩🇪61:5e:f0: 6f:29:8b:8a:70:af:44:16:b3:2b:27:6b:d6:63:e6: 65:81:ed:19:5c:18:12:31:77:64:30:a0:26:6b:fe: d8:c4:0e:72:f1:26:b4:50:96:d0:e9:b3:8c:c0:bf: a5:67:d5:5f:fc💿be:15:b9:db:6f:4b:eb:f3:85: bc:5d:ef:82:3f:56:09:cf:e4:3a:e6:f6:97:2b:a6: 17:70:5e:3e:76:f4:89:f7:af:ee:9e:6f:89:f6:0c: 2b:b3:3e:97:af:4a:e7:31:f8:39:3f:14:df:62🇩🇪 01:6b:fa:80:14:9c:9e:da:5f:48:7f:e5:8f:b2:02: 01:bf

Example parsing with the order switched:

openssl rsa -pubin -inform PEM -text -noout < test.pub Modulus (2048 bit): 00:c1:72:a6:ca:26:db:34:1e:8c:27:8d:d4:d6:0f: cd:05:16:55:95:a1:f0:a8:55:b4:a0:28:b1:db:bf: c5:df:f4:7b:b4:65:3f:31:5f:04:60:d8:d2:13:3a: 8a:58:93:78:68:a3:95:78:d8:72:0d:21:d5:f7:c3: a8:ae:7d:3a:ad:71:10:79:cf:8c:32:a3:95:16:92: 6d:63:1a:a3:55:e6:69:9a:37:0a:58:b6:44:dc:fe: be:39:12:d1:56:ef:15:99:8f:e4:ca:91:30:e8:e6: f5:fd:59:c5:17:61:53:b4:91:8d:df:53:8a:cc:b6: 4f:7b:c2:19:83:db:76:8b:44:55:85🇩🇪61:5e:f0: 6f:29:8b:8a:70:af:44:16:b3:2b:27:6b:d6:63:e6: 65:81:ed:19:5c:18:12:31:77:64:30:a0:26:6b:fe: d8:c4:0e:72:f1:26:b4:50:96:d0:e9:b3:8c:c0:bf: a5:67:d5:5f:fc💿be:15:b9:db:6f:4b:eb:f3:85: bc:5d:ef:82:3f:56:09:cf:e4:3a:e6:f6:97:2b:a6: 17:70:5e:3e:76:f4:89:f7:af:ee:9e:6f:89:f6:0c: 2b:b3:3e:97:af:4a:e7:31:f8:39:3f:14:df:62🇩🇪 01:6b:fa:80:14:9c:9e:da:5f:48:7f:e5:8f:b2:02: 01:bf Exponent: 65537 (0x10001)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ehampshirecommented, Mar 23, 2017

heh, that would be why they are backwards… wow, sorry about that. Can’t believe I missed that typo

0reactions
wbondcommented, Mar 23, 2017

You seem to be assigning the pub_mod to public_exponent and pub_exp to modulus.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to find modulus from a RSA public key?
The output a simple sequence of two integers. It's obvious which one is the modulus and which is the exponent. You actually can...
Read more >
what is the format of RSA public key modulus and exponent in ...
For Modulus , the RSAParameters structure expects the DER value but with the optional sign-padding 0x00 byte removed. For Exponent it's the same....
Read more >
RSA Public key - Page 2 — oracle-tech
I'm pretty much a newbie crypto guy, but I have learned that the exponent of the RSA public key is going to be...
Read more >
Exercise 1 – Perfect Secrecy
Encrypt your plaintext M using Alice public exponent/ What is the resulting ciphertext C? • Now Alice receives C. • Verify that Alice...
Read more >
RSA (cryptosystem) - Wikipedia
RSA (Rivest–Shamir–Adleman) is a public-key cryptosystem that is widely used for secure data ... key consists of the modulus n and the public...
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