3

I'm using Raw RSA encryption and decryption. tutorial and Raw RSA from the Crypto++ wiki to develop a simple code that encrypt/decrypt string using RSA using Crypto++.

I'm using Visual studio 2010. The code run without error. But, I don't understand what is the significant of n, e, d ? Why can't I change it?

I respected the algorithm of RSA and I chose this value:

    // La clé publique est la paire (e, n) et la clé secrète est d, donc aussi p et q.
    // p = 3, q = 11, n = 3 x 11, f = (11–1).(3–1) = 20. On choisit d=7 (7 et 20 sont bien premiers entre eux).
    // e = 3 car e.d= 20 * 1 + 1

But always I have debug error: enter image description here enter image description here

Can someone help me ?

xtensa1408
  • 584
  • 12
  • 32
  • 1
    http://stackoverflow.com/a/20114154/179910 covers some of the basic idea of how RSA works and the uses of the numbers you need to give it. – Jerry Coffin Sep 16 '14 at 21:42
  • The tutorial from JacobHacker just rips Crypto++'s work without attribution. You should probably avoid JacobHacker's stuff and stick with the Crypto++ wiki. – jww Sep 16 '14 at 21:46
  • *"The code run without error... But always I have debug error"* - well, which is it? If there is an error, please post it with the question. – jww Sep 16 '14 at 21:47
  • without error: when I run the code as published with error: when I chage the value of n, e and d – xtensa1408 Sep 16 '14 at 21:52
  • @Sadok - The images are too small. I can't read the error messages, even with my reading glasses. Its desirable to paste the text of the error message so it can be read by the folks trying to help you and searched by future visitors. – jww Sep 16 '14 at 22:44
  • @Sadok - please catch a `std::exception`. In the exception handler, perform `cerr << ex.what() << endl;`. Then paste the error message into your question. – jww Sep 16 '14 at 22:49
  • 1
    Raw, or "textbook" RSA is insecure. You should be padding your plaintext, unless this is an exercise and you are not worried about security. – Jim Flood Sep 18 '14 at 22:43

1 Answers1

0
 // p = 3, q = 11, n = 3 x 11, f = (11–1).(3–1) = 20. On choisit d=7
 //    (7 et 20 sont bien premiers entre eux).
 // e = 3 car e.d= 20 * 1 + 1

These parameters are artificially small. Probably too small.

One of the properties of RSA is the message size must be smaller than the modulus size. 3x11 = 33, and that's 25 (give or take). So your message must be smaller than 5 bits.

Crypto++ specifies messages sizes in bytes, not bits. So you will likely never be able to encrypt anything under the modulus of 33.

Unfortunately, the cited wiki page does not discuss that size_in_bits(message) < size_in_bits(modulus). And I can't change it at the moment because Crypto++ is broken for writes (reads are OK).

Also, here's from rsa.cpp:

if (modulusSize < 16)
  throw InvalidArgument("InvertibleRSAFunction: specified modulus size is too small");

So you should probably specify a modulus at least 216 in size. 216 is 65536.

Finally, until we see the relevant parts of your program and error message, this is just speculation.

jww
  • 97,681
  • 90
  • 411
  • 885
  • thank you I understand you. Can you please tell how can I convert c to char*: CryptoPP::Integer c = pubKey.ApplyFunction(m); It will be very nice if I complete my task this night before sleeping. – xtensa1408 Sep 16 '14 at 23:09