2013-04-30 101 views
1

這個代碼不兼容工作正常的Android應用程序,但是當我試圖與黑莓應用程序來使用我發現下面的錯誤jar文件與黑莓

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 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 

請幫我分揀我們的這個問題。

+1

黑莓Java是基本的Java 1.3中加入了一些RIM專有庫/ J2ME有[在Java中沒有KeySpec類1.3/J2ME或RIM的庫(HTTP。 ://www.blackberry.com/developers/docs/7.0.0api/index.html)。所以,您需要重寫該代碼才能將其移植到BlackBerry。 – Nate 2013-04-30 12:22:27

回答

2

BlackBerry基於Java 2 MicroEdition(J2ME),它是Java 2標準版(J2SE)的子集。

這意味着並非所有標準Java類都可以在BlackBerry上使用。因此,通常您不能在BlackBerry開發中使用標準Java庫。

在您的示例中,您試圖使用包java.security.spec中的類。但是該包不屬於J2ME,因此該類在BlackBerry手持設備上不存在。

見黑莓7的在線的JavaDoc documentaton:http://www.blackberry.com/developers/docs/7.0.0api/