Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:15:25+00:00 2026-06-01T20:15:25+00:00

What I am trying to do is read some PEM public keys using Python

  • 0

What I am trying to do is read some PEM public keys using Python GAE.

the RSAKey module does not parse PEM formatted public keys, just private.

If I can get the modulus and exponent from the PEM, I can go from there.

Exploring a typical PEM (of the sort I will be using) with openssl asn1parse I can find the BIT STRING where they live.

But I can’t figure out how to find them using the gdata ASN1Parser.

For example openssl output:

openssl asn1parse -i -in test.pem
 0:d=0  hl=3 l= 159 cons: SEQUENCE          
 3:d=1  hl=2 l=  13 cons:  SEQUENCE          
 5:d=2  hl=2 l=   9 prim:   OBJECT            :rsaEncryption
16:d=2  hl=2 l=   0 prim:   NULL              
18:d=1  hl=3 l= 141 prim:  BIT STRING

And then drilling down I can see the RSA Modulus and Exponent:

openssl asn1parse -strparse 18 -i -in test.pem 
  0:d=0  hl=3 l= 137 cons: SEQUENCE          
  3:d=1  hl=3 l= 129 prim:  INTEGER           :09C7A8007111B2B...
135:d=1  hl=2 l=   3 prim:  INTEGER           :010001

If I then take this same PEM and in Python stick it into bytes, how do I get the correct child to get these values?

asn1 = ASN1Parser(bytes)
modulus = asn1.getChild(1).getChild(0).value
exponent = asn1.getChild(1).getChild(1).value
binascii.hexlify(modulus)

Or what? I can’t figure out what level, etc I need to look. I also don’t really know what I’m doing… Using hexlify I can see the values in there, but always (playing with child, and depth) with extra stuff in front, and/or not the full number as shown in openssl.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:15:26+00:00Added an answer on June 1, 2026 at 8:15 pm

    I modified tlslite to do what you are talking about… Here’s a snippet that should help you out. “bytes” is the DER encoded public key.

    I think the problem that you are having is that some keys may have “padding”. The padding length is the first byte of the payload. You’ll then need to skip the padding bytes and that many bytes of padding.

    @staticmethod
    def parseDERPublicKey(bytes):
        a = ASN1Parser(bytes)
        b = a.getChild(1)
        padding = b.value[1]
        # TODO: I am assuming padding is 0, this is wrong.
        #       Skip the padding as well.
        c = b.value[1:] # get the mod/exp portion after the padding
        d = ASN1Parser(c)
    
        modulus = bytesToNumber(d.getChild(0).value)
        exponent = bytesToNumber(d.getChild(1).value)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read some data from a python module from a web.
I am trying to read some settings from php.ini using zend. The API that
I am trying to read some smps files with python, and found a fortran
I am trying to read some info from a text file by using windows
I'm trying to have python read some lines of text from a file and
I am trying to read some Fortran code, but can not determine what the
I'm new to Python and I'm trying to read some values from an USB
I'm getting something pretty strange going on when trying to read some data using
I am trying to read some code that I did not write. In the
I'm trying to read some JSON data from the Tumblr API. I'm using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.