Android Open Source - nsa-away Display Plaintext Activity






From Project

Back to project page nsa-away.

License

The source code is released under:

GNU General Public License

If you think the Android project nsa-away 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

/*
 * Copyright 2014 individual contributors as indicated by the @author 
 * tags/* w w w.  j a v  a 2  s . c  om*/
 * 
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>. 
 */
package org.sector67.nsaaway;

import org.sector67.nsaaway.android.AlertUtils;
import org.sector67.nsaaway.key.KeyUtils;
import org.sector67.otp.cipher.CipherException;
import org.sector67.otp.cipher.OneTimePadCipher;
import org.sector67.otp.encoding.EncodingException;
import org.sector67.otp.encoding.SimpleBase16Encoder;
import org.sector67.otp.envelope.EnvelopeUtils;
import org.sector67.otp.key.KeyException;
import org.sector67.otp.key.KeyStore;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 
 * @author scott.hasse@gmail.com
 * 
 */
public class DisplayPlaintextActivity extends Activity {

  private String ciphertext;
  private String keyName;
  private int offset;
  private int length;
  private KeyStore ks;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_display_plaintext);

    Button eraseKeyAndContinueButton = (Button) findViewById(R.id.eraseKeyAndContinueButton);

    Intent i = getIntent();
    ciphertext = i.getStringExtra(MainActivity.CIPHERTEXT_KEY);
    keyName = i.getStringExtra(MainActivity.KEYNAME_KEY);
    offset = i.getIntExtra(MainActivity.OFFSET_KEY, 0);

    TextView plaintextView = (TextView) findViewById(R.id.displayPlaintext);
    String result = "UNKNOWN";
    try {
      ks = KeyUtils.getKeyStore(getApplicationContext());
      OneTimePadCipher cipher = new OneTimePadCipher(ks);
        String noEnvelope = EnvelopeUtils.getBody(ciphertext);
      SimpleBase16Encoder encoder = new SimpleBase16Encoder();
      Log.e("Debug envelope", noEnvelope);

      byte[] decoded = encoder.decode(noEnvelope);
      length = decoded.length;
      result = cipher.decrypt(keyName, offset, decoded);
    } catch (KeyException e) {
      result = e.getMessage();
    } catch (CipherException e) {
      result = e.getMessage();
    } catch (EncodingException e) {
      result = e.getMessage();
    }
    /*
     * FileUtils fileUtils =
     * FileUtilsFactory.getBuildAppropriateFileUtils(getApplicationContext
     * ()); result = result + fileUtils.getBuild() + "\n";
     * 
     * for (int j = 0; j < dirs.length; j++) { result = result + "\n" +
     * dirs[j].getAbsolutePath(); }
     */
    plaintextView.setText(result);

      //Listen for a button event
      eraseKeyAndContinueButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
              try {
                //clear the text view so navigating back will not display the message
                TextView plaintextView = (TextView) findViewById(R.id.displayPlaintext);
                plaintextView.setText("");
            ks.eraseKeyBytes(keyName, offset, length);
              Toast.makeText(getApplicationContext(), getString(R.string.message_key_bytes_erased), Toast.LENGTH_SHORT).show();
                    Intent nextScreen = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(nextScreen); 
                  } catch (KeyException e) {
            AlertUtils.createAlert(getString(R.string.error_erasing_key_bytes), e.getMessage(), DisplayPlaintextActivity.this).show();
          }

            }
      });
  }

}




Java Source Code List

org.sector67.nsaaway.CreateAKeyActivity.java
org.sector67.nsaaway.DisplayCiphertextActivity.java
org.sector67.nsaaway.DisplayPlaintextActivity.java
org.sector67.nsaaway.EnterCiphertextActivity.java
org.sector67.nsaaway.EnterPlaintextActivity.java
org.sector67.nsaaway.KeyChooserActivity.java
org.sector67.nsaaway.KeyChooserDialogFragment.java
org.sector67.nsaaway.KeyManagerActivity.java
org.sector67.nsaaway.MainActivity.java
org.sector67.nsaaway.SettingsActivity.java
org.sector67.nsaaway.SettingsFragment.java
org.sector67.nsaaway.SimpleOCRActivity.java
org.sector67.nsaaway.android.AlertUtils.java
org.sector67.nsaaway.file.AbstractFileUtils.java
org.sector67.nsaaway.file.DirectoryChooserActivity.java
org.sector67.nsaaway.file.FileUtilsFactory.java
org.sector67.nsaaway.file.FileUtils.java
org.sector67.nsaaway.file.KitKatFileUtils.java
org.sector67.nsaaway.file.LegacyFileUtils.java
org.sector67.nsaaway.key.KeyUtils.java
org.sector67.nsaaway.ocr.complex.BeepManager.java
org.sector67.nsaaway.ocr.complex.CaptureActivityHandler.java
org.sector67.nsaaway.ocr.complex.CaptureActivity.java
org.sector67.nsaaway.ocr.complex.DecodeHandler.java
org.sector67.nsaaway.ocr.complex.DecodeThread.java
org.sector67.nsaaway.ocr.complex.FinishListener.java
org.sector67.nsaaway.ocr.complex.HelpActivity.java
org.sector67.nsaaway.ocr.complex.LuminanceSource.java
org.sector67.nsaaway.ocr.complex.OcrCharacterHelper.java
org.sector67.nsaaway.ocr.complex.OcrInitAsyncTask.java
org.sector67.nsaaway.ocr.complex.OcrRecognizeAsyncTask.java
org.sector67.nsaaway.ocr.complex.OcrResultFailure.java
org.sector67.nsaaway.ocr.complex.OcrResultText.java
org.sector67.nsaaway.ocr.complex.OcrResult.java
org.sector67.nsaaway.ocr.complex.PlanarYUVLuminanceSource.java
org.sector67.nsaaway.ocr.complex.PreferencesActivity.java
org.sector67.nsaaway.ocr.complex.ViewfinderView.java
org.sector67.nsaaway.ocr.complex.camera.AutoFocusManager.java
org.sector67.nsaaway.ocr.complex.camera.CameraConfigurationManager.java
org.sector67.nsaaway.ocr.complex.camera.CameraManager.java
org.sector67.nsaaway.ocr.complex.camera.PreviewCallback.java
org.sector67.nsaaway.ocr.complex.camera.ShutterButton.java
org.sector67.nsaaway.ocr.complex.language.LanguageCodeHelper.java