I'm trying to sign/verify data between a C application and a Java application.

In java for now I was using the built-in JCE provider with SHA256withRSA as algorithm. On the C part I'm using OpenSSL RSA_sign/RSA_verify methods with NID_sha256 as type.

With this configuration I can't verify in my java application data signed from the C one and vice versa. It seems that SHA256withRSA is using PKCS#1 v1.5 and openssl state that they use PKCS# 2.0 as padding (source).

This is why I think that the problem could come from this padding difference, but I can't find any JCE provider that support the v2.0 padding.

Is this correct? What is the difference between these paddings?

  • $\begingroup$ I edited your question to ask a slightly different question that the answer below answers. This is because the original question was in my opinion off topic as it was a programming problem to be solved. If you disagree, you can roll back my edit. $\endgroup$ – otus Nov 20 '15 at 7:53
  • $\begingroup$ No, you are right, this is a good edit ! $\endgroup$ – darkheir Nov 20 '15 at 8:49

Your problem is not with the signature scheme, something else is wrong.

RSA is specified by the RSA cryptography standard, PKCS#1 (mirrored in various RFC's). The PKCS#1 v1.5 padding was introduced in version 1.5 but it persisted in 2.0, 2.1 and 2.2. Those did however introduce a more secure padding scheme called PSS.

Unfortunately nobody calls the signature generation schemes by their true name: RSASSA-PKCS1-v1_5. Both your C code and your Java code seem to use that signature scheme.

  • $\begingroup$ You can post code to stackoverflow so the crypto guys there can check what goes wrong, if possible with test material (keys, input & signature values). $\endgroup$ – Maarten Bodewes Nov 19 '15 at 23:38
  • $\begingroup$ Thank you, I didn't find anywhere in wich version PSS was introduces so I thaught it could be in 2.0 since it's a major version. I'll try to investigate a little more and if I didn't find anything I follow your advice ! $\endgroup$ – darkheir Nov 20 '15 at 8:49
  • $\begingroup$ @darkheir PKCS#1v2.0 adds OAEP for encryption and v2.1 adds PSS for signature; details are in http://tools.ietf.org/html/rfc3447 . But that API in OpenSSL (RSA_sign/verify) only does original 'type 1' padding, now retronymed RSASSA-PKCS1-v1_5 as Maarten says. (Other APIs support more paddings, though for compability both v1.5 schemes, type 1 and type 2, are named simply 'pkcs1' which can be confusing.) In Java, SunRsaSign supports only v1.5 padding, although you can add BouncyCastle to get PSS. I concur your problem is something else. $\endgroup$ – dave_thompson_085 Nov 20 '15 at 23:27
  • $\begingroup$ Yeah you were right, I checked with the developer in charge of the C part and he had to correct some stuff. Now everything is working well! $\endgroup$ – darkheir Nov 22 '15 at 22:17
  • $\begingroup$ @darkheir As long as it's working...I hope I helped a bit by excluding the signature scheme. $\endgroup$ – Maarten Bodewes Nov 22 '15 at 23:09

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.