Android Open Source - easypgp Encrypt Email






From Project

Back to project page easypgp.

License

The source code is released under:

GNU General Public License

If you think the Android project easypgp 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 com.sawyer.easypgp;
// www . j  a v a2s  .  co m
import android.annotation.SuppressLint;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

public class EncryptEmail {
   KeyPairGenerator kpg;
   KeyPair kp;
   PublicKey pubKey;
   PrivateKey privKey;
   byte[] encryptedBytes, decryptedBytes;
   Cipher cipher, cipher1;
   String[] encrypted;

   @SuppressLint("TrulyRandom")
public String[] Encrypt(final String plainText)
         throws NoSuchAlgorithmException, NoSuchPaddingException,
         InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
      kpg = KeyPairGenerator.getInstance("RSA");
      kpg.initialize(1024);
      kp = kpg.genKeyPair();
      pubKey = kp.getPublic();
      privKey = kp.getPrivate();

      cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.ENCRYPT_MODE, pubKey);
      encryptedBytes = cipher.doFinal(plainText.getBytes());
      for (int i = 0; i<encryptedBytes.length; i++){
         System.out.println(encryptedBytes[i]);
      }
      try {
         if (encryptedBytes != null) {
            System.out.println("Yes, encryptedBytes exists.");
            encrypted[0] = new String(encryptedBytes);
            System.out.println(encrypted[0]);
         }
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      try {
         encrypted[1] = new String(privKey.getEncoded());
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      // Log.d("EasyPGP.Encrypt", encrypted[0]);
      return encrypted;
   }

}




Java Source Code List

.GmailInbox.java
com.sawyer.adapters.EmailArrayAdapter.java
com.sawyer.easypgp.AppPreferences.java
com.sawyer.easypgp.DecodeFragment.java
com.sawyer.easypgp.EncryptEmail.java
com.sawyer.easypgp.GmailInbox.java
com.sawyer.easypgp.InboxFragment.java
com.sawyer.easypgp.MainActivity.java
com.sawyer.easypgp.NavigationDrawerFragment.java
com.sawyer.easypgp.NfcActivity.java
com.sawyer.easypgp.ShareKeyFragment.java
com.sawyer.easypgp.SingleEmailFragment.java
com.sawyer.gmail.GmailSender.java
com.sawyer.gmail.JSSEProvider.java
com.sawyer.handlers.onClickHandlers.java