Android Open Source - android-passwordKeeper A E S256






From Project

Back to project page android-passwordKeeper.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions...

If you think the Android project android-passwordKeeper 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 Cody Munger//from w ww .j a  v a  2  s.  com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.munger.passwordkeeper.struct;


/**
 * Wrapper for the JNI AES and MD5 calls.
 * This class provides functionality for the Advanced Encryption Standard algorithms and the MD5 hash algorithm.
 * Run ndk_build in the jni folder to regenerate the library for this wrapper.
 * The library is located in libs/armeabi/libaes256.so
 */
public class AES256 
{
  //load up the library
  static{
    System.loadLibrary("aes256");
  }

  /** The password to use for encryption and decryption */ private String password;
  /** A pointer containing the C object that does the encryption */ private int context;
  
  /**
   * Initialize the AES objects with the provided password
   * @param password any plaintext password will do.  They are converted to an MD5 hash before being used by AES.
   */
  public AES256(String password)
  {
    this.password = password;
    context = init(password);
  }
  
  /**
   * Take care of the leftover C variables when this object is garbage collected.
   */
  @Override
  protected void finalize() throws Throwable 
  {
    destroy(context);
    super.finalize();
  };
  
  /**
   * encode the provided string to ciphertext
   * @param target the plaintext to encode
   * @return encoded ciphertext converted to hex notation
   */
  public String encode(String target)
  {
    return encode(context, target);
  }
  
  /**
   * decode the provided ciphertext to plaintext
   * @param target the hex encoded ciphertext previously generated by the encode function
   * @return plaintext decoded from the ciphertext
   */
  public String decode(String target)
  {
    return decode(context, target);
  }
  
  /**
   * Initialize the AES encryption object
   * @param password the plaintext password to use as the encryption key
   * @return a C pointer to the AES object
   */
  private native int init(String password);
  
  /**
   * Clean up the AES object.
   * Free any allocated variables
   * @param context the C pointer returned by init
   */
  private native void destroy(int context);
  
  /**
   * Encrypt the provided plaintext
   * @param context the AES object C pointer returned by init
   * @param target the plaintext to convert
   * @return ciphertext encoded in hex or null on failure
   */
  private native String encode(int context, String target);
  
  /**
   * Decrypt the provided ciphertext
   * @param context the AES object C pointer returned by init
   * @param target the ciphertext to convert
   * @return plaintext or null on failure
   */
  private native String decode(int context, String target);
}




Java Source Code List

com.munger.passwordkeeper.MainActivity.java
com.munger.passwordkeeper.SplashScreen.java
com.munger.passwordkeeper.alert.AlertFragment.java
com.munger.passwordkeeper.alert.ConfirmFragment.java
com.munger.passwordkeeper.alert.InputFragment.java
com.munger.passwordkeeper.alert.PasswordFragment.java
com.munger.passwordkeeper.struct.AES256.java
com.munger.passwordkeeper.struct.PasswordDetails.java
com.munger.passwordkeeper.struct.PasswordDocumentDropbox.java
com.munger.passwordkeeper.struct.PasswordDocumentFile.java
com.munger.passwordkeeper.struct.PasswordDocument.java
com.munger.passwordkeeper.view.AboutFragment.java
com.munger.passwordkeeper.view.CreateFileFragment.java
com.munger.passwordkeeper.view.ImportFileFragment.java
com.munger.passwordkeeper.view.SelectFileFragment.java
com.munger.passwordkeeper.view.ViewDetailFragment.java
com.munger.passwordkeeper.view.ViewFileFragment.java
com.munger.passwordkeeper.view.widget.DetailItemWidget.java
com.munger.passwordkeeper.view.widget.FileItemWidget.java
com.munger.passwordkeeper.view.widget.TextInputWidget.java
com.munger.passwordkeeper.view.widget.TextWidget.java