Mohit Saxena
Mohit Saxena

Reputation: 11

jar file not compatible with blackberry

This code is working fine with android application but when i try to use with blackberry application i have found below error

CODE :

import java.math.BigInteger; 
import java.security.KeyFactory; 
import java.security.interfaces.RSAPublicKey; 
import java.security.spec.*; 
import javax.crypto.Cipher;

public class OxiSecurity {

public String encryption(String text)
{
    byte[] bb={},cc=new byte[128];
    String s1=null;
    String s2=null;
    byte[] cipherData={} ;
      try
      {
          BigInteger modulus = new BigInteger("C60ADE82F8922A025ED9BBD02E8D6C0AAEBA2F387E9E83D1A0A530E7E7FF8A6B7F4C86233AFEFB97C3F606D6CD76B4A3BAF3F93AE79C16E3FB764C1DCBB73744A5C2C2F3ED878FF5181A558A8917CA1164BFE0A088F13859FA22D1A48362051407523E0E11AC90E18FC4CBFD70DBC2149EF62316DC063C647A3319E96B7727EB",16);
          BigInteger pubExp = new BigInteger("65537");
          KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
          RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(modulus, pubExp);
          RSAPublicKey key = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);
          System.out.print(key);
          Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
          cipher.init(Cipher.ENCRYPT_MODE, key);
          cipherData = cipher.doFinal(text.getBytes());   
          char[] c=new char[128];
             for(int i=0;i<128;i++)
             {
                 if(cipherData[i]<0)
                     c[i]=(char)(cipherData[i]+256);
                 else
                     c[i]=(char)cipherData[i];
             }
            s2= new String(String.copyValueOf(c)); 
            char[] my = s2.toCharArray();

             for(int i=0;i<128;i++)
             {
                 if((int)my[i]>0)
                     cc[i]=(byte)(my[i]-256);
                 else
                     cc[i]=(byte)my[i];
             }

          s1 = new String(cipherData);
         System.out.print(s1);
         bb=s1.getBytes();
          //String s=s1;
         String s = new String(cipherData, "UTF8");
          return s2;
      }
      catch(Exception e)
      {
          e.printStackTrace();
      }   
      finally
      {

          return s2;
      }
}

}

ERROR : once i tried to verified this jar for blackberry app

Error preverifying class com.xxxxx.oxisecurity.OxiSecurity VERIFIER ERROR
com/xxxx/oxisecurity/OxiSecurity.encryption(Ljava/lang/Stri ng;)Ljava/lang/String;:
Cannot find class java/security/spec/KeySpec

Please help me sort our this problem.

Upvotes: 1

Views: 201

Answers (1)

Robert
Robert

Reputation: 42799

BlackBerry bases on the Java 2 MicroEdition (J2ME) which is a subset of the Java 2 Standard Edition (J2SE).

This means that not all standard Java classes you know are available on BlackBerry. Therefore usually you can not use standard Java libraries for BlackBerry development.

In your example you are trying to use a class from the package java.security.spec. But that package is not part if of J2ME, therefore the class does not exists on BlackBerry handhelds.

See online JavaDoc documentaton of BlackBerry 7: http://www.blackberry.com/developers/docs/7.0.0api/

Upvotes: 2

Related Questions