Android Open Source - ShhApp R S A Asynck Task






From Project

Back to project page ShhApp.

License

The source code is released under:

Apache License

If you think the Android project ShhApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.shhapp;
//from   w w  w . j a  va2 s  . c om
import java.math.BigInteger;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.widget.EditText;
import android.widget.Toast;

public class RSAAsynckTask extends AsyncTask<Integer, Boolean, String> {
  private ProgressDialog progress;
  private Activity shhActivity;
  private BigInteger encrypt = null;
  private BigInteger decrypt = null;
  private EditText messageTxt;
  private  RSA key;
  public RSAAsynckTask(ShhActivity shhActivity){
    this.shhActivity = shhActivity;
    this.messageTxt = shhActivity.messageTxt;
  }
  protected void onPreExecute() {
    // Show progress Dialog here
    super.onPreExecute();

    // create ProgressDialog here ...
    progress = new ProgressDialog(shhActivity);
    progress.setTitle("Shh.. ");
    progress.setMessage("Shh.. Encrytion in Progress!!");
    // set other progressbar attributes
    progress.setIndeterminate(true);
    progress.setCancelable(false);
    progress.show();

  }

  @Override
  protected String doInBackground(Integer... params) {
    key = new RSA();
    System.out.println(key);
    // create random message, encrypt.
    String s = messageTxt.getText().toString();
    BigInteger message = new BigInteger(s.getBytes());
    encrypt = key.encrypt(message);
    System.out.println("message   = " + message);
    System.out.println("hexa dicimal form of message " + message.toString(16));
    System.out.println("encrpyted = " + encrypt);
    shhActivity.runOnUiThread(new Runnable() {
      public void run() {
        messageTxt.setText(encrypt + "");
      }
    });
    return encrypt+"";
  }
  
  public void decryptSMS() {
    if (key != null) {
      decrypt = key.decrypt(encrypt);
      messageTxt.setText(new String(decrypt.toByteArray()));
      System.out.println("decrypted = " + decrypt);
      System.out.println("after decrypt the message is "
          + new String(decrypt.toByteArray()));
    }
  }
  @Override
  protected void onPostExecute(final String success) {
    if (progress.isShowing()) {
      progress.dismiss();
    }
    if (success != null) {
      Toast.makeText(shhActivity, "Encryption Success", Toast.LENGTH_LONG)
      .show();
    } else
      Toast.makeText(shhActivity, "Encryption fails", Toast.LENGTH_LONG).show();
  }
}




Java Source Code List

com.example.shhapp.Contact.java
com.example.shhapp.DatabaseHelper.java
com.example.shhapp.GMailSenderAsynTask.java
com.example.shhapp.GmailReciever.java
com.example.shhapp.MessageUtil.java
com.example.shhapp.RSAAsynckTask.java
com.example.shhapp.RSA.java
com.example.shhapp.ShhActivity.java
com.internal.utility.GMailUtil.java
com.internal.utility.JSSEProvider.java