RSA Public Key Encryption
Posted: Sun May 29, 2016 2:07 pm
Hello
i want to encrypt some bytes for example (11 11 11 11 11) by using RSA Public Key with 2048 bit length , but the result changes ever
byte[] list = new byte[256];
private static Cipher asymCipher;
private static RSAPrivateKey rsaPriKey;
private static RSAPublicKey rsaPubKey;
private static KeyPair keyPair;
public testSignApplet()
{
rsaPriKey = (RSAPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE,KeyBuilder.LENGTH_RSA_2048,false);
rsaPubKey = (RSAPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC,KeyBuilder.LENGTH_RSA_2048,false);
keyPair = new KeyPair(rsaPubKey,rsaPriKey);
asymCipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1,false);
}
switch (buf[ISO7816.OFFSET_INS])
{
case (byte)0x0C:
keyPair.genKeyPair();;
case (byte)0x3C:
asymCipher.init(rsaPubKey,Cipher.MODE_ENCRYPT);
break;
case (byte)0x4C:
apdu.setIncomingAndReceive();
asymCipher.doFinal(buf,(short)ISO7816.OFFSET_CDATA,lc,list,(short)0);
apdu.setOutgoing();
apdu.setOutgoingLength((short)256);
apdu.sendBytesLong(list,(short)0,(short)list.length);
break;
}
i want to encrypt some bytes for example (11 11 11 11 11) by using RSA Public Key with 2048 bit length , but the result changes ever
byte[] list = new byte[256];
private static Cipher asymCipher;
private static RSAPrivateKey rsaPriKey;
private static RSAPublicKey rsaPubKey;
private static KeyPair keyPair;
public testSignApplet()
{
rsaPriKey = (RSAPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE,KeyBuilder.LENGTH_RSA_2048,false);
rsaPubKey = (RSAPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC,KeyBuilder.LENGTH_RSA_2048,false);
keyPair = new KeyPair(rsaPubKey,rsaPriKey);
asymCipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1,false);
}
switch (buf[ISO7816.OFFSET_INS])
{
case (byte)0x0C:
keyPair.genKeyPair();;
case (byte)0x3C:
asymCipher.init(rsaPubKey,Cipher.MODE_ENCRYPT);
break;
case (byte)0x4C:
apdu.setIncomingAndReceive();
asymCipher.doFinal(buf,(short)ISO7816.OFFSET_CDATA,lc,list,(short)0);
apdu.setOutgoing();
apdu.setOutgoingLength((short)256);
apdu.sendBytesLong(list,(short)0,(short)list.length);
break;
}