# RSA encryption error

**864325**May 25, 2011 5:42 PM

Hi everybody,

I'm a student who is programming on Java card (Javacard 2.2.2 with cref) for a master thesis. here is my problem: I try to write an exponential modular method on the javacard but it isn't working! Here is my method:

Do you have an idea?

Thank you

PS: I don't have the JCOp tools, so it's very annoying to debug the applet every time. I don't have it because I don't know where to download it and activate it.

Edited by: 861322 on May 25, 2011 7:41 PM

I'm a student who is programming on Java card (Javacard 2.2.2 with cref) for a master thesis. here is my problem: I try to write an exponential modular method on the javacard but it isn't working! Here is my method:

```
public static byte[] modPow(byte[] base, byte[] pow, byte[] mod){
byte[] result = new byte[mod.length];
// generate own rsa_keypair
KeyPair rsa_KeyPair;
RSAPublicKey rsa_PublicKey;
Cipher cipherRSA;
//generate the key (e, n) such that c = m^e mod n
rsa_KeyPair= new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1024);
rsa_PublicKey = (RSAPublicKey) rsa_KeyPair.getPublic();
rsa_PublicKey.setExponent(pow, (short)0, (short)pow.length);
rsa_PublicKey.setModulus(mod, (short)0, (short)mod.length);
//prepare the modPow operation
cipherRSA = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
cipherRSA.init(rsa_PublicKey, Cipher.MODE_ENCRYPT);
//perform the modPow
cipherRSA.doFinal(base, (short)0, (short)base.length, result, (short) 0);
return result;
}
```

So, I try just ```
public static byte[] modPow(byte[] base, byte[] pow, byte[] mod){
byte[] result = new byte[mod.length];
// generate own rsa_keypair
KeyPair rsa_KeyPair;
//generate the key (e, n) such that c = m^e mod n
rsa_KeyPair= new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1024);
return result;
}
```

and it's not working at all :-(Do you have an idea?

Thank you

PS: I don't have the JCOp tools, so it's very annoying to debug the applet every time. I don't have it because I don't know where to download it and activate it.

Edited by: 861322 on May 25, 2011 7:41 PM

I have the same question Show 0 Likes (0)