JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html

RSA Decryption Problem

JavaCard Applet Development Related Questions and Answers.
nikonai
Posts: 17
Joined: Mon Feb 22, 2016 4:37 am
Points :177
Contact:

RSA Decryption Problem

Post by nikonai » Thu Jul 27, 2017 11:30 pm

I generate RSA Key and get Public Key from my applet. I encrypt
"13131313131313130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
data with another tool with public key of my applet. My applet can decrypt this data perfectly.

But when I encrypt
"FAFAFAFAFAFAFAFA0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
data and send it to my applet to decrypt it, however my applet cannot decrypt it correctly, it returns a different data.

Where did I make a mistake? Please give me some clues.

Code about decryption:

Code: Select all

private void key_load (APDU apdu)
{
        byte [] apduBuffer = apdu.getBuffer();
        apdu.setIncomingAndReceive();

        cipherRSA2.init(PrivateKey, Cipher.MODE_DECRYPT);
        cipherRSA2.doFinal(apduBuffer, (short)ISO7816.OFFSET_CDATA, (short)64, apduBuffer, (short)ISO7816.OFFSET_CDATA);

        apdu.setOutgoingAndSend((short)5, (short)70);         

}

chico0609
Posts: 59
Joined: Mon Sep 14, 2015 5:05 am
Points :416
Contact:

Re: RSA Decryption Problem

Post by chico0609 » Fri Jul 28, 2017 2:51 am

The problem may be because when you converted the text you are encrypting in the second example to a number, the result is a negative number. Since RSA works by converting the key and text into large integers and performing a mathematical operation on them.

You might be better off using something like PKCS#1 padding

nikonai
Posts: 17
Joined: Mon Feb 22, 2016 4:37 am
Points :177
Contact:

Re: RSA Decryption Problem

Post by nikonai » Fri Jul 28, 2017 3:25 am

Thank you for your kind answer, chico0609.

I have found the problem. It is surely caused by the PKCS1 padding.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 17 guests

JavaCard OS : Disclaimer