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 7966729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:30:40+00:00 2026-06-04T06:30:40+00:00

I am newbie in cryptography and pycrypto. I have modulus n and private exponent

  • 0

I am newbie in cryptography and pycrypto.

I have modulus n and private exponent d. From what I understand after reading some docs private key consists of n and d.

I need to sign a message and I can’t figure out how to do that using pycrypto. RSA.construct() method accepts a tuple. But I have to additionally provide public exponent e to this method (which I don’t have).

So here is my question. Do I have to compute e somehow in order to sign a message?

It seems I should be able to sign a message just by using n and d (that constitute private key). Am I correct? Can I do this with pycrypto?

Thanks in advance.

  • 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-04T06:30:41+00:00Added an answer on June 4, 2026 at 6:30 am

    Actually for decrypting a message encrypted with the public key it’s enough to have the private exponent.

    That also means you can sign a message, because signing basically is just *de*crypting the plaintext with the private key, which when *en*crypted with the public key will give the plaintext again. Usually you use a hash digest on the plaintext before and sign that…

    The reason why you can’t decrypt a message uing only n and d with pyrcypto is that it does a blinding step during message decryption, which involves the public exponent, but isn’t really needed for the decryption.

    But by using some calls to the private API this step can be bypassed.

    Therefore this should work:

    from Crypto.PublicKey import RSA
    from Crypto.Util.number import bytes_to_long, long_to_bytes
    
    full = RSA.generate(2048)
    
    # construct key using only n and d
    try:
        # pycrypto >=2.5, only tested with _slowmath
        impl = RSA.RSAImplementation(use_fast_math=False)
        partial = impl.construct((full.n, 0L))
        partial.key.d = full.d
    except TypeError:
        # pycrypto <=2.4.1
        partial = RSA.construct((full.n, 0L, full.d))   
    
    
    
    pub = full.publickey()
    
    # create message with padding
    # http://en.wikipedia.org/wiki/RSA_%28algorithm%29#Padding_schemes
    cleartext = ...
    
    signature = partial.sign(cleartext, None)
    
    print "validating message: ", pub.verify(cleartext, signature)
    
    
    message = pub.encrypt(cleartext, None)
    
    # bypassing the blinding step on decrypt
    enc_msg=map(bytes_to_long, message)
    dec_msg = map(partial.key._decrypt, enc_msg)
    
    print "decrypting: "
    for m in dec_msg:
        print long_to_bytes(m)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question here but for some reason I cant figure this out. I have
newbie question I have a multiselect box that i populate with some ajax and
Newbie with databases, I would like some advise please.. I have agencies who can
I am a newbie in cryptographic system but i have seen many sources tell
Newbie question... The objective: I intend to have an HTML text input field as
newbie for clearcase. Since clearcase's config is rather different from other concept in git,
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Newbie here, I have a struct for a word, which contains a char array
newbie doing Java homework here. I have one class named Album which contains the
newbie programmer here. I have 3 tables namely product, category, and subcategory. I configured

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.