cannot send out sms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nickyeng
    Contributor
    • Nov 2006
    • 252

    cannot send out sms

    I have this following code which it makes me cannot send sms in my j2me application.


    Code:
    import com.sun.midp.ssl.CryptoException;
    
    public class Encrypter {
    	
    	public static String toHexString(byte [] ab) {
    		StringBuffer sb = new StringBuffer(ab.length * 2) ;
    
    		 for(int i=0; i<ab.length; ++i) {
    		 String sTemp = Integer.toHexString(0xFF & ab[i]) ;
    		 if(1==sTemp.length()) {
    		 sb.append("0") ;
    		 }
    		 sb.append(sTemp) ;
    		 }
    		 System.out.println(sb.toString());
    		 
    		 return sb.toString() ;
    		 }
    
    	public static String genHash(String s)
    		  {
    			 
    		
    		 byte[] ab = new byte[25];
    		
    		 try {
    			 com.sun.midp.ssl.MessageDigest md = com.sun.midp.ssl.MessageDigest.getInstance(com.sun.midp.ssl.MessageDigest.ALG_SHA, true);
    			
    			 md.update(s.getBytes(), 0, s.length()) ;
     
    			 System.out.println("in genHash method");
    			 System.out.println("\t" + s);
    			 System.out.println("\t" +md);
    		
    			 short sh = md.doFinal(s.getBytes(), 0, s.length(), ab, 0 );
    			
    			 System.out.println("\tsh = "+ sh);
    			 
    		 } catch (CryptoException e) {
    			
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		 } catch (Exception e) {
    			 e.printStackTrace();
    		 }
     
    		 
    		 return toHexString(ab) ;
    	}
    
    }
    In my main class code i call this:

    Code:
    // the following line of code somehow hit error in my phone but not in Eclipse emulator.
    String enc = Encrypter.genHash("SMS ME 12 12");
    
    // String enc = "nwjefjf2wejfjwefjj23rj23jr32jf23f23f23jf23j";
    
    boolean sent = message.sendSMS(smsc_number, enc);
    		 				if(sent==true) {
    		 					Alert info1=new Alert("Message Sent", enc ,null,AlertType.CONFIRMATION);
    		 					info1.setTimeout(5000); 	
    		 					display.setCurrent(info1,menu_list);	
    		 				} else {
    		 					Alert info2=new Alert("Sending Fail", "Could not sending out messsage.", null, AlertType.CONFIRMATION);
    		 					info2.setTimeout(5000);
    		 					display.setCurrent(info2, menu_list);
    		 				}
    when i click send button, my phone fail to sms out.

    instead i test with

    String enc = "nwjefjf2wejfjw efjj23rj23jr32j f23f23f23jf23j" ;

    it successfully send out.

    So the problem is in that Encrypter class.

    Can anyone know where is wrong?

    kindly
    nickyeng
Working...