package sketch.avengergear.com;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;

import org.spongycastle.jce.provider.BouncyCastleProvider;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Security;
import java.security.SecureRandom;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;

public class sketchUI extends Activity
{
    private static final String TAG = "SKETCH-UI";

    static {
        Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        try { 
            // Create the public and private keys
            KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "BC");

            SecureRandom random = new SecureRandom();
            generator.initialize(2048, random);
            KeyPair keyPair = generator.genKeyPair();

            byte[] pri = keyPair.getPrivate().getEncoded();
            byte[] pub = keyPair.getPublic().getEncoded();

            Log.v(TAG, keyPair.getPrivate().toString() );

        } catch (NoSuchProviderException e) {
            Log.e(TAG, "No provider exception", e);
        } catch (NoSuchAlgorithmException e) { 
            Log.e(TAG, "No Algorithum exception", e);
        }
        
        String uuid = UUID.randomUUID().toString();
        
        Log.v(TAG,"uuid = " + uuid);

    }
}


@@ -254,16 +254,48 @@
 til.Log;
+%0Aimport android.widget.TextView;
 %0A%0Aimport
@@ -740,32 +740,60 @@
 viderException;%0A
+import javax.crypto.Cipher;%0A
 import java.util
@@ -1409,17 +1409,17 @@
 %22RSA%22, %22
-B
+S
 C%22);%0A%0A  
@@ -1589,18 +1589,31 @@
     
-byte%5B%5D pri
+//PrivateKey privateKey
  = k
@@ -1662,56 +1662,940 @@
     
-byte%5B%5D pub = keyPair.getPublic().getEncoded();%0A%0A
+//PublicKey publicKey  = keyPair.getPublic().getEncoded();%0A            PrivateKey privateKey = keyPair.getPrivate();%0A            PublicKey publicKey  = keyPair.getPublic();%0A%0A            Log.v(TAG, keyPair.getPrivate().toString() );%0A%0A            String uuid = UUID.randomUUID().toString();%0A            %0A            Log.v(TAG,%22uuid = %22 + uuid);%0A%0A            String testText = %22Avenger testing the MoJo%22;%0A            TextView original_textview = (TextView)findViewById(R.id.original_tv);%0A            original_textview.setText(%22%5BORIGINAL%5D:%5Cn%22 + testText + %22%5Cn%22);%0A%0A            // Encode the original data with RSA public key%0A            byte%5B%5D encoded = null;%0A            try %7B%0A                Cipher rsa_cipher = Cipher.getInstance(%22RSA/None/PKCS1Padding%22, %22SC%22);%0A                rsa_cipher.init(Cipher.ENCRYPT_MODE, publicKey);%0A                encoded = rsa_cipher.doFinal(testText.getBytes());%0A            %7D catch (Exception e) %7B%0A    
     
@@ -2610,51 +2610,853 @@
 Log.
-v
+e
 (TAG, 
-keyPair.getPrivate().toString() 
+%22RSA encryption error%22, e);%0A            %7D%0A%0A            TextView encoded_textview = (TextView)findViewById(R.id.encoded_tv);%0A            encoded_textview.setText(%22%5BENCODED%5D:%5Cn%22 + %0A            Base64.encodeToString(encoded, Base64.DEFAULT) + %22%5Cn%22);%0A%0A            // Decode the encoded data with RSA public key%0A            byte%5B%5D decoded = null;%0A            try %7B%0A                Cipher rsa_cipher = Cipher.getInstance(%22RSA/None/PKCS1Padding%22, %22SC%22);%0A                rsa_cipher.init(Cipher.DECRYPT_MODE, privateKey);%0A                decoded= rsa_cipher.doFinal(encoded);%0A            %7D catch (Exception e) %7B%0A                Log.e(TAG, %22RSA decryption error%22, e);%0A            %7D%0A            TextView decoded_textview = (TextView)findViewById(R.id.decoded_tv);%0A            decoded_textview.setText(%22%5BDECODED%5D:%5Cn%22 + new String(decoded) + %22%5Cn%22
 );%0A%0A
+%0A
     
@@ -3665,116 +3665,8 @@
   %7D%0A
-        %0A        String uuid = UUID.randomUUID().toString();%0A        %0A        Log.v(TAG,%22uuid = %22 + uuid);%0A%0A
     

Create TextView sample for encode and decoding text