简体   繁体   English

jar文件与黑莓手机不兼容

[英]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 这段代码在android应用程序中正常工作,但是当我尝试在blackberry应用程序中使用时,发现以下错误

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 错误:一旦我尝试为Blackberry应用验证此罐子

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. 请帮助我解决这个问题。

BlackBerry bases on the Java 2 MicroEdition (J2ME) which is a subset of the Java 2 Standard Edition (J2SE). BlackBerry基于Java 2 MicroEdition(J2ME),它是Java 2 Standard Edition(J2SE)的子集。

This means that not all standard Java classes you know are available on BlackBerry. 这意味着并非您知道的所有标准Java类都可以在BlackBerry上使用。 Therefore usually you can not use standard Java libraries for BlackBerry development. 因此,通常您不能将标准Java库用于BlackBerry开发。

In your example you are trying to use a class from the package java.security.spec. 在您的示例中,您尝试使用包java.security.spec中的类。 But that package is not part if of J2ME, therefore the class does not exists on BlackBerry handhelds. 但是该软件包不是J2ME的一部分,因此该类在BlackBerry手持设备上不存在。

See online JavaDoc documentaton of BlackBerry 7: http://www.blackberry.com/developers/docs/7.0.0api/ 请参阅BlackBerry 7的在线JavaDoc文档: http : //www.blackberry.com/developers/docs/7.0.0api/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM