Crypto API for J2ME

I am writing an application that does digital signature on palm platform. The intention is to allow the user to store his private key on the palm device so that he could perform signing anywhere. The private key does not leave the palm device - the hashed data to be signed is beamed to the palm via IR, the my app performs the signing and finally beam the signature back the the original device.

can anyone advise on what API's that I need ?

[463 byte] By [eeti] at [2007-9-26 1:49:36]
# 1
I've been using the Bouncy Castle J2ME Cryptography API. It is downloadable from www.bouncycastle.orgLet me know if this helps.cbaldys
cbaldys at 2007-6-29 2:55:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Thanks, it's cool
eeti at 2007-6-29 2:55:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

Hi cbaldys,

I am now testing the BouncyCastle to do RSA key pair generation (using the Java Wireless ToolKit on my PC, not on Palm device).

The key generation process takes forever to generate a 1024-bit RSA key pair.

However, when I test it with JDK, it took about 20 seconds.

Someone suggests to me that the BouncyCastle's java.math.BigInteger class is not as fast as JDK's.

Have anyone tried anything similar?

eeti at 2007-6-29 2:55:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

i m also working on the same line

i have been using Bouncy castle API for encryption,decryption can any body tell me how to genearate digital signature and specially how to read certificates in j2me?

actually i have to do smime implementaion jo j2me that using BC api that's y i m asking all this

plz help me

regards

aqeel

aqeel_1982 at 2007-6-29 2:55:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

I have used the api but only DES cipher works on http connection when i use other des blowfish and so on locally i get the right answer but over http i cannot recover the base message. How to achive this:

do i write something wrong ?

here is the server code:

import org.bouncycastle.util.encoders.*;

import java.io.*;

import org.bouncycastle.crypto.*;

import org.bouncycastle.crypto.paddings.*;

import org.bouncycastle.crypto.engines.*;

import org.bouncycastle.crypto.modes.*;

import org.bouncycastle.crypto.params.*;

public class Encryptor {

private BufferedBlockCipher cipher;

private KeyParameterkey;

public static final byte TYPE_DES = 1;

public static final byte TYPE_AES = 2;

public static final byte TYPE_TWOFISH = 3;

public static final byte TYPE_BLOWFISH = 4;

public static final byte TYPE_SERPENT = 5;

public static final byte TYPE_SKIPJACK = 6;

// Initialize the cryptographic engine.

// The key array should be at least 8 bytes long.

public Encryptor ( byte[] key , byte cipherType){

BlockCipher theCipher = null;

switch (cipherType){

case TYPE_DES:

theCipher = new DESEngine ();

break;

case TYPE_AES:

theCipher = new RijndaelEngine ();

break;

case TYPE_TWOFISH:

theCipher = new TwofishEngine ();

break;

case TYPE_BLOWFISH:

theCipher = new BlowfishEngine ();

break;

case TYPE_SERPENT:

theCipher = new SerpentEngine();

break;

case TYPE_SKIPJACK:

theCipher = new SkipjackEngine ();

break;

};

//cipher = new PaddedBlockCipher (

//new CBCBlockCipher (

//theCipher) );

cipher = new CTSBlockCipher(new CBCBlockCipher (theCipher)) ;

this.key = new KeyParameter ( key );

}

// Initialize the cryptographic engine.

// The string should be at least 8 chars long.

public Encryptor ( String key , byte cipherType){

this ( key.getBytes (), cipherType );

}

// Private routine that does the gritty work.

private byte[] callCipher ( byte[] data )

throws CryptoException {

intsize =

cipher.getOutputSize ( data.length );

byte[] result = new byte[ size ];

intolen = cipher.processBytes ( data, 0,

data.length, result, 0 );

olen += cipher.doFinal ( result, olen );

if( olen < size ){

byte[] tmp = new byte[ olen ];

System.arraycopy (

result, 0, tmp, 0, olen );

result = tmp;

}

return result;

}

// Encrypt arbitrary byte array, returning the

// encrypted data in a different byte array.

public synchronized byte[] encrypt ( byte[] data )

throws CryptoException {

if( data == null || data.length == 0 ){

return new byte[0];

}

cipher.init ( true, key );

return callCipher ( data );

}

// Encrypts a string.

public byte[] encryptString ( String data )

throws CryptoException {

if( data == null || data.length () == 0 ){

return new byte[0];

}

byte[] result = null;

try{

result = data.getBytes ("UTF-8");

}catch (UnsupportedEncodingException e){

result = data.getBytes () ;

}

return encrypt ( result );

}

public String encryptStrings ( String data )

throws CryptoException {

if( data == null || data.length () == 0 ){

return new String ();

}

byte[] result = null;

try{

result = data.getBytes ("UTF-8");

}catch (UnsupportedEncodingException e){

result = data.getBytes () ;

}

byte[] encrypted = encrypt ( result );

return new String (encrypted);

}

// Decrypts arbitrary data.

public synchronized byte[] decrypt ( byte[] data )

throws CryptoException {

if( data == null || data.length == 0 ){

return new byte[0];

}

cipher.init ( false, key );

return callCipher ( data );

}

// Decrypts a string that was previously encoded

// using encryptString.

public String decryptString ( byte[] data )

throws CryptoException {

if( data == null || data.length == 0 ){

return "";

}

String result = null;

try{

result = new String ( decrypt ( data ),"UTF-8" );

}catch (UnsupportedEncodingException e){

result = new String ( decrypt ( data ));

}

return result;

}

}

and the invoke method:

Encryptor encryptor = new Encryptor( theCipherKey ,Encryptor.TYPE_DES);

out.write(encrypted.getBytes());

response.setContentLength(encrypted.getBytes().length);

out.flush();

out.close();

mchmiel21 at 2007-6-29 2:55:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

i m also working on the same line

i have been using Bouncy castle API for encryption,decryption can any body tell me how to genearate digital signature and specially how to read certificates in j2me?

actually i have to do smime implementaion jo j2me that using BC api that's y i m asking all this

plz help me

regards

aqeel

aqeel_1982 at 2007-6-29 2:55:41 > top of Java-index,Java Mobility Forums,Java ME Technologies...