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

  • SEARCH
  • Home
  • 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 1011351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:13:13+00:00 2026-05-16T09:13:13+00:00

I am using RSA to encrypt/decrypt my session keys in Python. I am using

  • 0

I am using RSA to encrypt/decrypt my session keys in Python. I am using Pycrypto library. After generating the keypair, I want to extract the private key and public key from that generated key and store them in different files. How can I do this? I can see the has Private method which can tell that the generated keypair has private component but not able to find how to extract both the keys from this generated keypair. Any Suggestion would be of great help.

  • 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-05-16T09:13:14+00:00Added an answer on May 16, 2026 at 9:13 am

    If you want to get the different parts from the key, there is key attribute for that:

    >>> from Crypto.PublicKey import RSA
    >>> RSAkey = RSA.generate(1024)
    >>> getattr(RSAkey.key, 'n')
    13773...L
    >>> getattr(RSAkey.key, 'p')
    11731...L
    >>> getattr(RSAkey.key, 'q')
    11740...L
    

    Available components are ‘n’, ‘e’, ‘d’, ‘p’, ‘q’, ‘u’

    If you just want to save it in PEM, you should use exportKey() method (available since 2.2)

    >>> private = RSA.generate(1024)
    >>> public  = private.publickey()
    >>> private.exportKey()
    '-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDo1M0P3nryaF8ZITv8vCFVnjUJ1mnIsrqXZRTzjin69xepr3cz\nKicG3EYSUqMODQAsvMj0tGMo+ElGOVOkPFLVVBHd8izgA/E1RqUzbUDMj4WnhlhA\nQq7tNaViOXNaZ7krJZHabZKxfYvLAQtm4tr+m5NtXPBaWvjwhd5M9xvktwIDAQAB\nAoGBANVsS1Rikbymo5V7e2teYAgFb4THAEyyWIvyYlQnWp/r48rtRoyl9QQ64hhl\nm4WDsUdQ/bwhpkul3DT804jWqu2V71p68rQP7h5D6ldCBUr5nQc9o/uEyy4YCgxD\n/ZxNiY5Bb/lMP9nhb2NbG4184mhUMHu+06wWX6RrXQtMtjYhAkEA8DioToMZIy3s\nhPohri3CAgByV2Jxf7JPqVZ93JjlSlBz+aybSv1mOJUPRFpkMk2xiPmHtEn16hYr\nesVK11tcjwJBAPgf4QYAw9dV+DuVqdwz+kmTjnlkr0Q7fjaGfl60DWmuLWmxiRhe\nMYQ2+8iyPDmxcPFTGSpGqyvyJDjQ/wOlWVkCQQCRIuotZW/OnXSFc0reHa9V3kc3\nHLdOW8FdonAw0//Uwn8PnoXE7QzRqt2qgqJ+8goNpBWli/oUEIj8iC8LpptpAkBV\nFFlMfaaph8j+ZWtBHnGMGRSZe3S9qMi2WZerUYHn4tmfjEi+Gk5QT6o2Pyd3gOiB\nV0Uhwemfv/+7m65VybTBAkEA5H59kG+B9HHD5hJtksAtMh8dxk/MI8G0csduU0vu\n7K5ejL522XsHurVrWdqnk6KvjlRXqB4FsMWLE6RBgBNV0A==\n-----END RSA PRIVATE KEY-----'
    >>> public.exportKey()
    '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDo1M0P3nryaF8ZITv8vCFVnjUJ\n1mnIsrqXZRTzjin69xepr3czKicG3EYSUqMODQAsvMj0tGMo+ElGOVOkPFLVVBHd\n8izgA/E1RqUzbUDMj4WnhlhAQq7tNaViOXNaZ7krJZHabZKxfYvLAQtm4tr+m5Nt\nXPBaWvjwhd5M9xvktwIDAQAB\n-----END PUBLIC KEY-----'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Looks good to me. I'd suggest one minor refactoring in… May 16, 2026 at 5:09 pm
  • Editorial Team
    Editorial Team added an answer There is no need to install the swift plugin. Swift… May 16, 2026 at 5:09 pm
  • Editorial Team
    Editorial Team added an answer No. HtmlHelper are extension methods of the MVC.ViewPage and MVC.ViewPage.… May 16, 2026 at 5:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to encrypt and decrypt data using RSA in C#. I have the
As the title says. Using the iPhone SDK, I want to RSA encrypt some
I'm using RSA to encrypt communication between a server and a client. Lets say
Or concrete - I am using this javascript RSA library for the client side
Where can I find a RSA encrypt example that does not use NoPadding? --update
What is the difference between encrypting some data vs signing some data (using RSA)?
Using CF8 and MySQL 5.1, I am trying to encrypt() a password upon creation
Like in the title, I want to encrypt data, which is sent over network.
How can I fill RSA structure with xml-formatted public key for using with RSA
I'm creating a x509 certificate using makecert with the following parameters: makecert -r -pe

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.