I'm trying to implement RSA without using any java libraries using the algorithm from wikipedia HERE

So, anyone can clearly see that it is a raw RSA, and can directly be attacked.

The question is how can i include padding to the algorithm because i'm not using Java libraries, so what is the simple algorithm to implement the RSA padding to make it secure against some attacks?

Also, would Padding alone be enough? or there is something else i need to know?

Any help is appreciated. Thank you.

  • $\begingroup$ For signatures you could use full-domain-hash (FDH). For encryption you could use hybrid encryption based on RSA-KEM. $\endgroup$ – CodesInChaos Feb 12 '15 at 20:31
  • $\begingroup$ @CodesInChaos Thank you for your reply. I'm implementing both RSA and AES/CBC/PKCS5PADDING. But i think my RSA is raw i have implemented what is written from wikipedia. So i was wondering if there something to make sure that RSA could be even more securer? like adding padding? $\endgroup$ – Deyaa Feb 12 '15 at 20:44
  • $\begingroup$ @Deyaa, what are the key sizes for your implementation? Are you going to code the multiple precision arithmetic for doing large multiplications and reductions? If yes, this is an instructive job, but difficult to test, and then after in a second step, thinking about implementing countermeasure against all the know attacks. $\endgroup$ – Robert NACIRI Feb 12 '15 at 20:48
  • $\begingroup$ @RobertNACIRI The minimum key size for RSA is 1024 and can be raised to 2048 if needed. They key size for AES is 128. And no for the second question. $\endgroup$ – Deyaa Feb 12 '15 at 20:53
  • 1
    $\begingroup$ See PKCS#1. It describes industry-standard RSA padding, for signature with appendix, and encryption. In fact, two versions for each, including one with a modern security argument. $\endgroup$ – fgrieu Feb 12 '15 at 21:08

Do not use raw RSA at all.

First simple attack starts when (plain ^ public_exponent) < n , i.e. when the message to be encrypted is small. Then there are more sophisticated attacks and forgeries as soon as 1 plain text and the corresponding cipher text are known, or even can be guessed. And then you have to review all possible attacks on RSA for the last 30+ years. No way.

Implement padding pkcs#1 named RSA-OAEP (based on MGF function, a variant of a feistel cipher).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.