Android Open Source - nsa-away Key Manager 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/*from  w ww  . j a va2 s . co m*/
 * 
 * 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 java.util.Iterator;
import java.util.List;

import org.sector67.nsaaway.android.AlertUtils;
import org.sector67.nsaaway.key.KeyUtils;
import org.sector67.otp.key.FileKeyStore;
import org.sector67.otp.key.KeyException;
import org.sector67.otp.key.KeyStore;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

/**
 * 
 * @author scott.hasse@gmail.com
 *
 */
public class KeyManagerActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_key_manager);

        Button createTestKeys = (Button) findViewById(R.id.createTestKeysButton);
        Button listKeys = (Button) findViewById(R.id.listKeysButton);
        Button createAKey = (Button) findViewById(R.id.createAKeyButton);
        //Button addAKey = (Button) findViewById(R.id.addAKeyButton);

    // Listen for a button event
        createTestKeys.setOnClickListener(new View.OnClickListener() {
      public void onClick(View arg0) {
        try {
          createTestKeys();
          Toast.makeText(getApplicationContext(), getString(R.string.message_test_keys_created), Toast.LENGTH_SHORT).show();
        } catch (KeyException e) {
          //Toast.makeText(getApplicationContext(), "Error creating test keys: " + e.getMessage(), Toast.LENGTH_LONG).show();
          AlertUtils.createAlert(getString(R.string.title_test_keys_creation_error), getString(R.string.message_test_keys_creation_error) + ": " + e.getMessage(), KeyManagerActivity.this).show();
        }
      }
    });

    // Listen for a button event
        listKeys.setOnClickListener(new View.OnClickListener() {
      public void onClick(View arg0) {
        try {
          List<String> keys = listKeys();
          String result = "";
          for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) {
            String key = (String) iterator.next();
            result = result + key + "\n";
          }
          AlertUtils.createAlert(getString(R.string.title_key_list), result, KeyManagerActivity.this).show();
        } catch (KeyException e) {
          //Toast.makeText(getApplicationContext(), "Error creating test keys: " + e.getMessage(), Toast.LENGTH_LONG).show();
          AlertUtils.createAlert("Test Key Creation Error", "An error occured while creating test keys: " + e.getMessage(), KeyManagerActivity.this).show();
        }
      }
    });
      // Listen for a button click on the encryption button
        createAKey.setOnClickListener(new View.OnClickListener() {
              public void onClick(View arg0) {
                  Intent nextScreen = new Intent(getApplicationContext(), CreateAKeyActivity.class); 
                  startActivity(nextScreen); 
              }
      });

  }

  
  private List<String> listKeys() throws KeyException {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String keyStorePath = sharedPref.getString(SettingsActivity.KEY_PREF_KEYSTORE_PATH, "");


      FileKeyStore store = new FileKeyStore(keyStorePath);
       store.init();
       List<String> keys = store.listKeys();
       return keys;
  }

  private void createTestKeys() throws KeyException {
    KeyStore store = KeyUtils.getKeyStore(this);
       store.deleteKey("encrypt-key");
       store.deleteKey("decrypt-key");
       store.deleteKey("alice-key");
       store.deleteKey("bob-key");
    store.generateKey("encrypt-key", 1000);
       store.copyKey("encrypt-key", "decrypt-key");
    store.generateKey("alice-key", 1000);
    store.generateKey("bob-key", 1000);
  }

}




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