Android Open Source - BlitzMail Crypto






From Project

Back to project page BlitzMail.

License

The source code is released under:

GNU General Public License

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

package de.grobox.blitzmail;
/*from   w ww.  j av a 2s  .com*/
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;

import android.content.Context;
import android.provider.Settings;
import android.util.Base64;

public class Crypto {

  private Context context;
  protected static final String UTF8 = "utf-8";

  public Crypto(Context context) {
    this.context = context;
  }

  @SuppressWarnings("deprecation")
  protected String encrypt( String value ) {
    try {
      final byte[] bytes = value!=null ? value.getBytes(UTF8) : new byte[0];
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
      SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PrivateConstants.CryptoKey));
      Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
      pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(Settings.Secure.getString(context.getContentResolver(),Settings.System.ANDROID_ID).getBytes(UTF8), 20));
      return new String(Base64.encode(pbeCipher.doFinal(bytes), Base64.NO_WRAP),UTF8);

    } catch( Exception e ) {
      throw new RuntimeException(e);
    }

  }

  @SuppressWarnings("deprecation")
  protected String decrypt(String value){
    try {
      final byte[] bytes = value!=null ? Base64.decode(value,Base64.DEFAULT) : new byte[0];
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
      SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PrivateConstants.CryptoKey));
      Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
      pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(Settings.Secure.getString(context.getContentResolver(),Settings.System.ANDROID_ID).getBytes(UTF8), 20));
      return new String(pbeCipher.doFinal(bytes),UTF8);

    } catch( Exception e) {
      throw new RuntimeException(e);
    }
  }
}




Java Source Code List

com.provider.JSSEProvider.java
de.grobox.blitzmail.AsyncMailTask.java
de.grobox.blitzmail.Crypto.java
de.grobox.blitzmail.EncryptedEditTextPreference.java
de.grobox.blitzmail.MailSender.java
de.grobox.blitzmail.MailStorage.java
de.grobox.blitzmail.MainActivity.java
de.grobox.blitzmail.NoteActivity.java
de.grobox.blitzmail.NotificationHandlerActivity.java
de.grobox.blitzmail.PrivateConstants.sample_java
de.grobox.blitzmail.SendActivity.java