0

I've just been looking into RSA encryption with C++ and am wanting to make a program that can en/decrypt files of my own custom file extension. Obviously I need to choose two primes numbers (for my p and q values) to encrypt and decrypt this file, but I am curious as to how I could stop these values being pulled out of my program via de-compiling.

Obviously, with the primes in hand, someone could easily calculate the necessary values for the private key that ONLY this executable should have.

Are there methods for somehow generating a random private key that will always unlock the public key?

kelalaka
  • 49,797
  • 12
  • 123
  • 211
Zaxter5
  • 3
  • 1

1 Answers1

2

You can't. If the user can run the software, they can extract the key from it. There is research on how to make it difficult to extract the key (white box cryptography), but it's not very successful.

You need to think about what do you want to accomplish. Does the user encrypt the files to themselves, so that they can decrypt it later? Then you could derive a symmetric key from a user's password. Does the user want to encrypt the file to someone else? Then each user should generate a private key (the primes) for themselves, and send their public keys to one another.

(In each scenario there are a lot of details you should take care of, so you're just scratching the surface of the problem)

Conrado
  • 6,614
  • 1
  • 30
  • 45