Variablen Unbekannter Fehler

Lucaaa

Bekanntes Mitglied
Hallo!
In folgender Klasse stürzt mine App beim klick auf den Button "btn_entschluesseln" ab. (Beim verschluesseln klappt alles).

Erstmal der Fehler:
Code:
11-16 22:37:21.199 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:21.199 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:21.202 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:21.202 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:21.205 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:21.205 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:25.127 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:25.127 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:25.161 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:25.161 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:25.168 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:25.168 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:25.186 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:37:25.186 29773-29773/com.ludevstudio.android.lutextcrypt E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-16 22:42:08.283 29773-29773/com.ludevstudio.android.lutextcrypt E/Editor: hideClipTrayIfNeeded() TextView is focused!! hideClipTray()
11-16 22:42:09.002 29773-29804/com.ludevstudio.android.lutextcrypt E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae977a70

Und die Klasse:
Java:
package com.ludevstudio.android.lutextcrypt;

import android.app.ProgressDialog;
import android.content.Context;
import android.icu.util.Output;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;

import android.os.Vibrator;
import lutextcrypt.java.luca.com.lutextcrypt.R;


public class RsakeygeneratorActivity extends AppCompatActivity implements View.OnClickListener {
    Toolbar toolbar;

    private RadioButton radio_512bits;
    private RadioButton radio_1024bits;
    private RadioButton radio_2048bits;
    private RadioButton radio_4096bits;
    private RadioButton radio_defaultfile;
    private RadioButton radio_costumfile;
    private EditText edt_pubkeyname;
    private EditText edt_prikeyname;
    private Button btn_generieren;

    private ProgressDialog progBuilder;

    Boolean vibrieren;
    int vibrationsdauer;

    // Variablen für generation
    int keylenght = 1024;
    KeyPair key = null;

    String fileName_pubKey = "RsaPublic.key";
    String fileName_priKey = "RsaPrivate.key";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rsakeygenerator);
            toolbar = (Toolbar) findViewById(R.id.toolbar_rsakeygenerator);
        setSupportActionBar(toolbar);
        initKomponenten();
    }
            Vibrator vibrator;

    private void initKomponenten() {
        edt_pubkeyname = (EditText) findViewById(R.id.editText_eingabe_pubkey_rsakeygenerator);
        edt_prikeyname = (EditText) findViewById(R.id.editText_eingabe_prikey_rsakeygenerator);
        edt_pubkeyname.setEnabled(false);
        edt_prikeyname.setEnabled(false);


        radio_512bits = (RadioButton) findViewById(R.id.checkBox_512bits_rsakeygenerator);
        radio_1024bits = (RadioButton) findViewById(R.id.checkBox_1024bits_rsakeygenerator);
        radio_2048bits = (RadioButton) findViewById(R.id.checkbox_2048bits_rsakeygenerator);
        radio_4096bits = (RadioButton) findViewById(R.id.checkbox_4096bits_rsakeygenerator);

        radio_512bits.setOnClickListener(this);
        radio_1024bits.setOnClickListener(this);
        radio_1024bits.setChecked(true);
        radio_2048bits.setOnClickListener(this);
        radio_4096bits.setOnClickListener(this);

        radio_defaultfile = (RadioButton) findViewById(R.id.checkbox_defaultfilename_rsakeygenerator);
        radio_costumfile = (RadioButton) findViewById(R.id.checkbox_costumfilename_rsakeygenerator);
        radio_defaultfile.setChecked(true);
        radio_defaultfile.setOnClickListener(this);
        radio_costumfile.setOnClickListener(this);

        btn_generieren = (Button) findViewById(R.id.button_generieren_rsakeygenerator);
        btn_generieren.setOnClickListener(this);

        vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        Bundle extras = getIntent().getBundleExtra("extras");
        vibrieren = extras.getBoolean("vibrieren");
        vibrationsdauer = extras.getInt("vibrationsdauer");

        progBuilder = new ProgressDialog(this);
        progBuilder.setCancelable(false);
        progBuilder.setTitle("generating keys");
        progBuilder.setMessage("please wait...");

    }


    @Override
    public void onClick(View v) {
       if(vibrieren)
           vibrator.vibrate(vibrationsdauer);

        int id = v.getId();

        if(id==R.id.checkBox_512bits_rsakeygenerator) {
            radio_1024bits.setChecked(false);
            radio_2048bits.setChecked(false);
            radio_2048bits.setChecked(false);
            keylenght = 512;
        } else if(id==R.id.checkBox_1024bits_rsakeygenerator) {
            radio_512bits.setChecked(false);
            radio_2048bits.setChecked(false);
            radio_2048bits.setChecked(false);
            keylenght = 1024;
        } else if(id==R.id.checkbox_2048bits_rsakeygenerator) {
            radio_1024bits.setChecked(false);
            radio_512bits.setChecked(false);
            radio_4096bits.setChecked(false);
            keylenght = 2048;
        } else if(id==R.id.checkbox_4096bits_rsakeygenerator) {
            radio_1024bits.setChecked(false);
            radio_2048bits.setChecked(false);
            radio_512bits.setChecked(false);
            keylenght = 4096;
        } else if(id==R.id.checkbox_defaultfilename_rsakeygenerator){
           radio_costumfile.setChecked(false);
            edt_pubkeyname.setEnabled(false);
            edt_prikeyname.setEnabled(false);
            fileName_pubKey = "Rsa-Public.key";
            fileName_priKey = "Rsa-Private.key";
        } else if (id==R.id.checkbox_costumfilename_rsakeygenerator) {
           radio_defaultfile.setChecked(false);
            edt_pubkeyname.setEnabled(true);
            edt_prikeyname.setEnabled(true);
            fileName_pubKey = edt_pubkeyname.getText().toString() + ".key";
            fileName_priKey = edt_prikeyname.getText().toString() + ".key";
        } else if(id==R.id.button_generieren_rsakeygenerator) {
                if(radio_costumfile.isChecked()) {
                        if(edt_pubkeyname.getText().toString().isEmpty() || edt_pubkeyname.getText().toString().contains(" ") || edt_prikeyname.getText().toString().isEmpty() || edt_prikeyname.getText().toString().contains(" ")   ){
                            Toast.makeText(getApplicationContext(), "Filenames can not be null or contain spaces", Toast.LENGTH_SHORT).show();
                        } else {

                            gen();
                            save();
                            Toast.makeText(this, "keys generated", Toast.LENGTH_SHORT).show();
                        }
                } else {
                    Toast.makeText(this, "keys generated", Toast.LENGTH_SHORT).show();
                    gen();
                    save();
                }
        }
    }

        private void gen() {
            KeyPairGenerator keyGen = null;

            try {
                keyGen = KeyPairGenerator.getInstance("RSA");
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            keyGen.initialize(keylenght);
            key = keyGen.generateKeyPair();
        }

        private void save() {
            File ordner_main = new File(Environment.getExternalStorageDirectory(), "LuTextCrypt");
            File ordner_rsakeys = new File(ordner_main, "RSA-Keys");
            File pubKey = new File(ordner_rsakeys, fileName_pubKey);
            File priKey = new File(ordner_rsakeys, fileName_priKey);
                if(!ordner_main.exists())
                    ordner_main.mkdirs();
                 if(!ordner_rsakeys.exists())
                 ordner_rsakeys.mkdirs();


            try {
                OutputStream fosPubKey = new FileOutputStream(pubKey);
                FileOutputStream fosPriKey = new FileOutputStream(priKey);
                fosPubKey.write(key.getPublic().getEncoded());
                fosPriKey.write(key.getPrivate().getEncoded());
                fosPubKey.close();
                fosPriKey.close();
            } catch (Exception e) {
                // Fehler
            }
                progBuilder.cancel();
        }

}
Danke schonmal!
 
Füg mal jedem EditText (edt_pubkeyname und edt_pubkeyname) im XML folgende Property hinzu:
XML:
android:inputType="textNoSuggestions"

PS: btn_entschluesseln gibt es in deinem Code nicht 😉
PPS: Falls der Error nicht weggehen sollte: Nutzt du eine 3rd-Party Tastatur wie SwiftKey?
 
Wie schaut denn die XML aus?
Daran dürfte es eigentlich nicht liegen da die edittexts für die filenamen garnicht gebraucht werden weil ja ein Standard festgelegt ist. Mit dem PublicKe funktioniert es ja und die privatekeyfile scheint auch gefunden zu werden sonst würde der Toast "privatekeyfile not found" ausgegeben werden (getestet). es muss an der Entschlüsselungsmethode liegen oder an den keys.

aber Hier trotzdem die XML
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" android:layout_height="match_parent">



    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_rsa"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:layout_alignParentTop="true"
        android:title="@string/rot13Activity_tilte"
        app:theme="@style/ToolBarStyle"
        android:background="?attr/colorPrimary"
        android:layout_centerHorizontal="true" />




    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="0dp"
        android:layout_below="@id/toolbar_rsa"
        android:background="@color/colorHintergrund"
        android:fillViewport="false"
        >
        xmlns:card_view="http://schemas.android.com/apk/res-auto"


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">




            <TextView
                android:id="@+id/textView8"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/colorTextfarbe"
                android:textSize="20dp"
                android:layout_margin="10dp"
                android:text="@string/allActivitys_eingabe_ueberschrift" />

            <EditText
                android:id="@+id/editText_eingabe_rsa"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:padding="10dp"
                android:maxLines="20"
                android:background="@color/colorTextfarbe"
                />





            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/colorTextfarbe"
                android:textSize="20dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="0dp"
                android:text="@string/allActivitys_filename_ueberschrift" />


            <android.support.v7.widget.AppCompatRadioButton
                android:id="@+id/checkbox_defaultfilename_rsa"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:textColor="@color/colorTextfarbe"
                android:textSize="20dp"
                app:buttonTint="@color/colorTextfarbe"
                android:text="@string/allActivitys_filename_default" />

            <android.support.v7.widget.AppCompatRadioButton
                android:id="@+id/checkbox_costumfilename_rsa"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:textColor="@color/colorTextfarbe"
                android:textSize="20dp"
                app:buttonTint="@color/colorTextfarbe"
                android:text="@string/allActivitys_filename_costum" />

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="*"
                android:shrinkColumns="*">

                <TableRow>

                    <EditText
                        android:id="@+id/editText_eingabe_pubkey_rsa"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="20dp"
                        android:layout_margin="10dp"
                        android:background="@color/colorTextfarbe"
                        android:maxLines="1"
                        android:padding="10dp"
                        android:inputType="textNoSuggestions"

                        android:hint="publickey"/>

                    <EditText
                        android:id="@+id/editText_eingabe_prikey_rsa"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="20dp"
                        android:layout_margin="10dp"
                        android:background="@color/colorTextfarbe"
                        android:maxLines="1"
                        android:padding="10dp"
                        android:inputType="textNoSuggestions"
                        android:hint="privatekey"/>


                </TableRow>

            </TableLayout>

            <Button
                android:id="@+id/button_verschluesseln_rsa"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="40dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_weight="0.06"
                android:background="@color/colorButtonfarbe"
                android:text="@string/allActivitys_btn_verschluesseln"
                android:layout_marginBottom="15dp"
                android:textColor="@color/colorTextfarbe"
                android:textAllCaps="false"
                android:textSize="20dp" />

            <Button
                android:id="@+id/button_entschluesseln_rsa"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_weight="0.06"
                android:background="@color/colorButtonfarbe"
                android:text="@string/allActivitys_btn_entschluesseln"
                android:layout_marginBottom="15dp"
                android:textColor="@color/colorTextfarbe"
                android:textAllCaps="false"
                android:textSize="20dp" />







            <TextView
                android:id="@+id/textView9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/colorTextfarbe"
                android:textSize="20dp"
                android:layout_margin="10dp"
                android:layout_marginBottom="0dp"
                android:text="@string/allActivitys_ausgabe_ueberschrift" />




            <TextView
                android:id="@+id/textview_ausgabe_rsa"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:textStyle="bold"
                android:padding="10dp"
                android:maxLines="30"
                android:textSize="20dp"
                android:background="@color/colorTextfarbe"
                />






        </LinearLayout>
    </ScrollView>






</RelativeLayout>
 
Wie in meinem ersten Post schon vermutet kann es gut an der SwiftKey Tastatur liegen.
Versuch mal auf die Standarttastatur zu wechseln und probier es dann noch mal. Wenn der Fehler weg ist hast du deine Fehlerquelle.
 
Wie in meinem ersten Post schon vermutet kann es gut an der SwiftKey Tastatur liegen.
Versuch mal auf die Standarttastatur zu wechseln und probier es dann noch mal. Wenn der Fehler weg ist hast du deine Fehlerquelle.
Hab ich versucht --> Feh(ler)lanzeige. Daran kann es eigentlich auch nicht liegen da im Code Default filenamen festgelegt sind und die Dateien ja gefunden werden. Meine Idee war, dass es an den Keys an sich liegen muss. Kann ich die irgendwie überprüfen?
 
Aber da waren auch andere Vorschläge als nur
Ich habe den Code jetzt (nur zum testen) umgeschrieben so dass die Files nicht benötigt werden. nun werden zufällige Keys generiert (wie gesagt nur im sicher zu stellen dass es nicht an den Keys liegt). der Fehler tritt weiterhin auf.
Es soll eine NullPointerException in der onClick-Methode geben.

Java:
package com.ludevstudio.android.lutextcrypt;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ContentResolver;
import android.content.Intent;
import android.os.Environment;
import android.os.Vibrator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.PathInterpolator;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import org.apache.commons.codec.binary.Base64;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;

import javax.crypto.Cipher;

import lutextcrypt.java.luca.com.lutextcrypt.R;

public class RsaActivity extends AppCompatActivity implements View.OnClickListener{
        EditText edt_eingabe;
        EditText edt_filename_pubKey;
        EditText edt_filename_priKey;
        TextView tw_ausgabe;
        Button btn_verschluesseln, btn_entschluesseln;
        Toolbar toolbar;
        RadioButton radio_filename_default, radio_filename_costum;


        Vibrator vibrator;
        Boolean vibrieren;
        int vibrationsdauer;

        File pubKeyfile, priKeyfile;
        PublicKey pubKey = null;
        PrivateKey priKey = null;
        File ordner_main, ordner_keys;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rsa);
            toolbar = (Toolbar) findViewById(R.id.toolbar_rsa);
            setSupportActionBar(toolbar);
                initKomponenten();



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_allactivities, menu);
        return true;
    }



    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(vibrieren)
            vibrator.vibrate(vibrationsdauer);
        int itemid = item.getItemId();
        if(itemid==R.id.allactivities_menu_item_clear) {
            clear();
        } else if(itemid==R.id.allactivities_menu_item_copy) {
            copy();
        }  else if(itemid==R.id.allactivities_menu_item_paste) {
            paste();
        } else if(itemid==R.id.allactivities_menu_item_share) {
            share();
        }

        return true;
    }





    private void initKomponenten() {
        edt_eingabe = (EditText) findViewById(R.id.editText_eingabe_rsa);
        edt_filename_pubKey = (EditText) findViewById(R.id.editText_eingabe_pubkey_rsa);
        edt_filename_priKey = (EditText) findViewById(R.id.editText_eingabe_prikey_rsa);
        tw_ausgabe = (TextView) findViewById(R.id.textview_ausgabe_rsa);
        radio_filename_default = (RadioButton) findViewById(R.id.checkbox_defaultfilename_rsa);
        radio_filename_costum = (RadioButton) findViewById(R.id.checkbox_costumfilename_rsa);
        radio_filename_default.setChecked(true);
        radio_filename_default.setOnClickListener(this);
        radio_filename_costum.setOnClickListener(this);
        btn_verschluesseln = (Button) findViewById(R.id.button_verschluesseln_rsa);
        btn_entschluesseln = (Button) findViewById(R.id.button_entschluesseln_rsa);
        btn_verschluesseln.setOnClickListener(this);
        btn_entschluesseln.setOnClickListener(this);

        vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
        Bundle extras = getIntent().getBundleExtra("extras");
        vibrieren = extras.getBoolean("vibrieren");
        vibrationsdauer = extras.getInt("vibrationsdauer");

        ordner_main = new File(Environment.getExternalStorageDirectory(), "LuTextCrypt");
        ordner_keys = new File(ordner_main, "RSA-Keys");
        pubKeyfile = new File(ordner_keys, "pub.key");
        priKeyfile = new File(ordner_keys, "pri.key");
    }

    @Override
    public void onClick(View v) {
        if(vibrieren)
            vibrator.vibrate(vibrationsdauer);

        int id = v.getId();
        if(id==R.id.checkbox_defaultfilename_rsa){
            radio_filename_default.setChecked(true);
            radio_filename_costum.setChecked(false);
            pubKeyfile = new File(ordner_keys, "Rsa-Public.key");
            priKeyfile = new File(ordner_keys, "Rsa-Private.key");

        } else if(id==R.id.checkbox_costumfilename_rsa) {
            radio_filename_default.setChecked(false);
            radio_filename_costum.setChecked(true);
            pubKeyfile = new File(ordner_keys, edt_filename_pubKey.getText().toString() + ".key");
            priKeyfile = new File(ordner_keys, edt_filename_priKey.getText().toString() + ".key");
        } else if (id == R.id.button_verschluesseln_rsa) {
           // pubKey = setPublicKey();
                gen();
            if (pubKey != null) {
                String encrypted = new String(verschluesseln(edt_eingabe.getText().toString().getBytes(), pubKey));
                String encoded = new String(android.util.Base64.encode(encrypted.getBytes(), 0));
                tw_ausgabe.setText(encoded);
            } else {
                Toast.makeText(this, "Publickeyfile not found", Toast.LENGTH_SHORT).show();
            }

        } else if (id == R.id.button_entschluesseln_rsa) {
          //  priKey = setPrivateKey();
            if (priKey != null) {
               String decoded = new String(android.util.Base64.decode(edt_eingabe.getText().toString().getBytes(), 0));
                String decrypted = new String(entschluesseln(decoded.getBytes(), priKey));
                tw_ausgabe.setText(decrypted);
            } else {
                Toast.makeText(this, "Privatekeyfile not found", Toast.LENGTH_SHORT).show();
            }

        }


        }






    private PublicKey setPublicKey() {
        byte[] keyBytes = new byte[(int) pubKeyfile.length()];
        try {
            BufferedInputStream bufPubKey = new BufferedInputStream(new FileInputStream(pubKeyfile));
            bufPubKey.read(keyBytes, 0, keyBytes.length);
            bufPubKey.close();

            X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
            KeyFactory kf = KeyFactory.getInstance("RSA");

            return kf.generatePublic(spec);
        } catch (Exception e) {
        }

        return null;
    }


    private byte[] verschluesseln(byte[] textBytes, PublicKey pubKey) {
        PublicKey key = pubKey;
       try {
           Cipher cipher = Cipher.getInstance("RSA");
           cipher.init(Cipher.ENCRYPT_MODE, key);
           return cipher.doFinal(textBytes);
       } catch (Exception e) {}
        return null;
    }


    private PrivateKey setPrivateKey() {
        byte[] keyBytes = null;
        try {
            keyBytes = new byte[(int) priKeyfile.length()];
            BufferedInputStream bufPriKey = new BufferedInputStream(new FileInputStream(priKeyfile));
            bufPriKey.read(keyBytes, 0, keyBytes.length);
            bufPriKey.close();

            X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
            KeyFactory kf = KeyFactory.getInstance("RSA");

            return kf.generatePrivate(spec);
        } catch (Exception e) {
        }

        return null;

    }



    private byte[] entschluesseln(byte[] textBytes, PrivateKey priKey) {
        PrivateKey key = priKey;
        try {
            Cipher cipher = Cipher.getInstance("RSA");
            cipher.init(Cipher.DECRYPT_MODE, key);
            return cipher.doFinal(textBytes);
        } catch (Exception e) {}
        return null;
    }


    public void copy() {
        Toast.makeText(getApplicationContext(), getString(R.string.allactivities_menu_item_copy), Toast.LENGTH_SHORT).show();
        String text = tw_ausgabe.getText().toString();
        android.content.ClipboardManager clipboard = (ClipboardManager) this.getSystemService(this.CLIPBOARD_SERVICE);
        ClipData clipDate = ClipData.newPlainText("text", text);
        clipboard.setPrimaryClip(clipDate);

    }

    public void paste() {
        Toast.makeText(getApplicationContext(), getString(R.string.allactivities_menu_item_paste), Toast.LENGTH_SHORT).show();
        android.content.ClipboardManager clipboard = (ClipboardManager) this.getSystemService(this.CLIPBOARD_SERVICE);
        ContentResolver contentResolver = this.getContentResolver();
        ClipData clipData = clipboard.getPrimaryClip();
        if(clipData !=null) {
            ClipData.Item item = clipData.getItemAt(0);
            CharSequence text = (String) item.getText();
            edt_eingabe.setText(text);
        }
    }

    public void clear() {
        Toast.makeText(getApplicationContext(), getString(R.string.allactivities_menu_item_clear), Toast.LENGTH_SHORT).show();
        edt_eingabe.setText(null);
        tw_ausgabe.setText(null);
    }

    public void share() {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, tw_ausgabe.getText().toString());
        sendIntent.setType("text/plain");
        startActivity(sendIntent);
    }





    public void gen() {
        KeyPair keyPair = null;
        KeyPairGenerator keyGen;
        try {
            keyGen = KeyPairGenerator.getInstance("RSA");
            keyGen.initialize(1024);
            keyPair = keyGen.generateKeyPair();
        } catch (Exception e) {}
            pubKey = keyPair.getPublic();
            priKey = keyPair.getPrivate();
        }

}
 
Dann Poste uns doch mal den Stacktrace.
kommt sofort...

Code:
1-17 17:36:33.931 11311-11311/com.ludevstudio.android.lutextcrypt E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                     Process: com.ludevstudio.android.lutextcrypt, PID: 11311
                                                                                     java.lang.ArrayIndexOutOfBoundsException: too much data for RSA block
                                                                                         at com.android.org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi.engineDoFinal(CipherSpi.java:459)
                                                                                         at javax.crypto.Cipher.doFinal(Cipher.java:1502)
                                                                                         at com.ludevstudio.android.lutextcrypt.RsaActivity.entschluesseln(RsaActivity.java:247)
                                                                                         at com.ludevstudio.android.lutextcrypt.RsaActivity.onClick(RsaActivity.java:165)
                                                                                         at android.view.View.performClick(View.java:5210)
                                                                                         at android.view.View$PerformClick.run(View.java:21328)
                                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5551)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
11-17 17:36:33.932 368-1357/? E/audio_hw_primary: select_devices: enter and usecase(1)
 

Zurück
Oben