Android Open Source - blargh Crypt






From Project

Back to project page blargh.

License

The source code is released under:

GNU General Public License

If you think the Android project blargh 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.travisbporter.blargh;
/*ww w . ja  v a 2  s  .co m*/
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;

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

public class Crypt {
  
  static KeyPair _keyPair;
  static public void genKey() throws NoSuchAlgorithmException, NoSuchPaddingException{
    _keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
  }
  static public byte[] encrypt(byte[] d) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException{
    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.ENCRYPT_MODE, _keyPair.getPublic());
    return cipher.doFinal(d);
  }
  static public byte[] decrypt(byte[] d) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException{
    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.DECRYPT_MODE, _keyPair.getPrivate());
    return cipher.doFinal(d);
  }
  
  static public String byteToString(byte[] d) throws UnsupportedEncodingException{
    return new String(d, "UTF-8");
  }
}




Java Source Code List

com.travisbporter.blargh.Beam.java
com.travisbporter.blargh.ChatFragment.java
com.travisbporter.blargh.Contact.java
com.travisbporter.blargh.Crypt.java
com.travisbporter.blargh.KeyFragment.java
com.travisbporter.blargh.MainActivity.java
com.travisbporter.blargh.PrefFragment.java