1

I generated an RSA public and private key pair using the pycryptodome module and returned the private key to the user. Now, for fetching some specific data, I need to validate the public and private key pair. I have both of them in bytes form:

public_key = b'-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlisb129W98LyU3caYcTr\nowqPJLUuaP9imnAOcJxzrKgK..........................qGUPMhPxVFA92mifqr9T2m5cI5/b\nCwIDAQAB\n-----END PUBLIC KEY-----'

private_key = bytes(input())

I need to create a function to check whether the private key entered by the user matches the public key stored by the program.

Devansh Singh
  • 134
  • 1
  • 10
  • You could import private and public key and then compare modulus and public exponent of both. If both match, both keys match. Apart from that: Why do you create the private key for the user? The user's private key should only be known by the user. – Topaco Jan 08 '22 at 08:37
  • @Topaco thank you, I'll try that! also I was just making some dummy projects for college work and thought of using RSA but got stuck here, so wanted to know how to proceed :) – Devansh Singh Jan 08 '22 at 10:14
  • did you find the solution for your problem? I am also looking for an answer to your question. – Koops Oct 11 '22 at 21:37

0 Answers0