Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 加密后发送短信不起作用_Java_Android_Function_Encryption - Fatal编程技术网

Java 加密后发送短信不起作用

Java 加密后发送短信不起作用,java,android,function,encryption,Java,Android,Function,Encryption,此函数将调用另一个函数(prince.Encrypt)对文本消息进行加密(prince算法)。但一旦与加密功能连接,发送短信就会失败。在包含加密之前,该函数工作正常 btnSendSMS.setOnClickListener(new View.OnClickListener() { public void onClick(View v, String args) {

此函数将调用另一个函数(prince.Encrypt)对文本消息进行加密(prince算法)。但一旦与加密功能连接,发送短信就会失败。在包含加密之前,该函数工作正常

    btnSendSMS.setOnClickListener(new View.OnClickListener() 
        {
             public void onClick(View v, String args) 
                  {             
                       String phoneNo = txtPhoneNo.getText().toString();
                       String message = txtMessage.getText().toString();              
                       if (phoneNo.length()>0 && message.length()>0)
                       {
                            LongBuffer messageBuf = TooLong.messageToLongBuffer(message); 
                            messageBuf.flip();
                            long[] messageData = new long[messageBuf.remaining()];
                            LongBuffer i = messageBuf.get(messageData);
                            String v1=prince.Encrypt(i, k0, kop, k1, t);
                            sendSMS(phoneNo, v1);
                        }               
                        else
                            Toast.makeText(getBaseContext(),"Please enter both phone number and message.",Toast.LENGTH_SHORT).show();
                  }

                  @Override
                  public void onClick(View v)
                  {
                  // TODO Auto-generated method stub
                  }
         });        
    }
 //---sends a SMS message to another device---
    private void sendSMS(String phoneNumber, String v1)
    {      
     /*
        PendingIntent pi = PendingIntent.getActivity(this, 0,
                new Intent(this, test.class), 0);                
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNumber, null, message, pi, null);        
        */

     String SENT = "SMS_SENT";
     String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
            new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

        //---when the SMS has been sent---
        registerReceiver(new BroadcastReceiver(){
   @Override
   public void onReceive(Context arg0, Intent arg1) {
    switch (getResultCode())
    {
        case Activity.RESULT_OK:
         Toast.makeText(getBaseContext(), "SMS sent", 
           Toast.LENGTH_SHORT).show();
         break;
        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
         Toast.makeText(getBaseContext(), "Generic failure", 
           Toast.LENGTH_SHORT).show();
         break;
        case SmsManager.RESULT_ERROR_NO_SERVICE:
         Toast.makeText(getBaseContext(), "No service", 
           Toast.LENGTH_SHORT).show();
         break;
        case SmsManager.RESULT_ERROR_NULL_PDU:
         Toast.makeText(getBaseContext(), "Null PDU", 
           Toast.LENGTH_SHORT).show();
         break;
        case SmsManager.RESULT_ERROR_RADIO_OFF:
         Toast.makeText(getBaseContext(), "Radio off", 
           Toast.LENGTH_SHORT).show();
         break;
    }
   }
        }, new IntentFilter(SENT));

        //---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver(){
   @Override
   public void onReceive(Context arg0, Intent arg1) {
    switch (getResultCode())
    {
        case Activity.RESULT_OK:
         Toast.makeText(getBaseContext(), "SMS delivered", 
           Toast.LENGTH_SHORT).show();
         break;
        case Activity.RESULT_CANCELED:
         Toast.makeText(getBaseContext(), "SMS not delivered", 
           Toast.LENGTH_SHORT).show();
         break;         
    }
   }
        }, new IntentFilter(DELIVERED));        

       SmsManager sms = SmsManager.getDefault();
       sms.sendTextMessage(phoneNumber, null, v1, sentPI, deliveredPI);               
    }    

}

超过160个字符吗?那样的话,你需要分开it@LittleChild不,我只是用了一个简短的文本“test”。举个例子就好了。“之前和之后的文本是什么样子的。@LittleChild纯文本可以是任何可以在手机中键入的内容,但为了测试,我使用的是“0”。加密文本应为“D9B4BD44C7E08B”。