# Verify Signature Failed [closed]

I am writing a small module which will verify signed message. Message will be signed using private key in Smart Card.

The inputs are:

1. Signed Message
2. Original Message
3. Public Key / Certificate with public key.

Signed Message and public key both will be in Hexadecimal form. I can retrieve the Public key from certificate.

I tried to verify using both Microsoft Crypto API and Openssl but each time it is failing to verify signature.

I guess the format of the data what I am getting is the main problem. Please go through the DATA and please help me how can I verify it.

You Can Find Data Here http://pastebin.com/ExYDcJ2t and code here http://pastebin.com/CdPkW8wp. Please Help me I need it urgently. Thank You

-
Welcome to Cryptography. Please note that your question is off topic according to the on-topic list. You can ask such questions on StackOverflow but please show the code in the question. –  Uwe Plonus Jun 20 '13 at 10:12
Thanks, and links i have pasted in the question itself. –  user2035532 Jun 20 '13 at 10:21

## closed as off topic by Hendrik Brummermann♦Jun 20 '13 at 15:40

Questions on Cryptography Stack Exchange are expected to relate to cryptography within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

You should have specification of the format of the data you process. Else, you have to resort to trial and guessing.

Which is easy here. In your test data, the public key $(n,e)$ is (b8f8dc2ca50384ba72c60e0389516f39a841e349b3f71431d343b7fc1f61c243b0779e19aff48b029972c117211d23daab53547433e4ab9d82d268339ab59c99cbf012e0f8444fe8913f60edcafa3b40bd645092d3c2c148ad243eca642c50a901b59ff4a446e584e9a4874186a17a7ffca6f0e0b1def0c1f25dc88416154de4df43433acdadecebaf1b9ca75c40dcae1f716ea4c60fdd3e3cc80d254c6174dfaaedb5d5b9066a8eb0b7c0e6c9bfdbb1072ea276aae7281c8d324eb3581d348996ed3eda29e01ec9c22e1819a6ba9132b78597879216c501b44f575c561bf5f46a296b2e518bf54c6fb8fdcb09d9fd66090449b6ba7ed0af703a51415aa504bf,010001).
The signature $s$ is 145F65CE7C2D8A0AFAB0FB86CE289084372D0463B235FA404AB635C890AF557FB1CAFEFD5BF91B7CDB7463BF165BB36DE82DB6D72E90AF0A5ECF7873E33702C2970EF9B3404C67CDE47CD94BD3C986518E1E8481B430AC689659CB63E5C82848C71DE8E9FCE8C9BE36330AF0A935C4D4BF6066215C418F4891D4BBAF75757AB32A8A28B830D1B46B6923822D28773005D5C9AB4117C1686DD9800FF2C1FC326E226127979CDDC35033AADBF4BA9829FA4FE2B4BCC59E9034F3BC3D780147AF9620066FF94130D73552D3DE85E3FE0BB7154D1A73B836F4A159A27E05508B52ACB4EF2DD9299DD9BBC8DFF367C5D1D9C00C6568A8129B24924EEB98D8B0D92E6A.

Computing $s^e\bmod n$ yields 0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF003021300906052B0E03021A05000414F7FF9E8B7BB2E09B70935A5D785E0CC5D9D0ABF0.

So with overwhelming certainty, this signature (mislabeled as SIGNED DATA-> in the pastebin) is formatted as per RSAES-PKCS1-V1_5 in PKCS#1, with 160-bit SHA-1 hash. See how $s^e\bmod n$ precisely is as defined by EMSA-PKCS1-V1_5, including the 0001FF..FF00 filler, the 3021300906052B0E03021A05000414 indicating SHA-1, and the final 20 bytes which are the SHA-1 of whatever data this signature is about the string Hello encoded in ASCII. The verification procedure for this signature is given in the aforementioned PKCS#1 reference. Sorry, I won't help with OpenSSL.

-
Thanks for Help,but the certificate i have says Signature Algo. is SHA256RSA and Hash algo. is SHA256. –  user2035532 Jun 20 '13 at 12:55
Also as u have experience in smart card system.DATA i am getting is from smart card application.Private Key is somewhere in smart card.and Off-Card application is signing DATA with PIN. –  user2035532 Jun 20 '13 at 12:59
@user2035532: The signature that you posted is internally labeled as using SHA-1 (that's the meaning of 3021300906052B0E03021A05000414; further the following seems like a 160-bit hash). No SHA-256 in sight. BTW this signature is mislabeled as SIGNED DATA->, but really is the signature of some signed data; I have no idea what this signed data is, nor what this signature attests, nor what the certificate you are talking about is, much less what it is meaning. –  fgrieu Jun 20 '13 at 14:29
@user2035532: Stating that data is from a Smart Card is as non-specific as stating it is from a portable computer. What kind of Smart Card? According to what specification? –  fgrieu Jun 20 '13 at 15:42
Thank You very Much.Its SHA-1 only.and good thing its working with same code just replacing SHA256 with SHA-1.Finally Signature is verified.Thank You Again. :) –  user2035532 Jun 21 '13 at 13:46