Android Open Source - schat Key Pair Manager






From Project

Back to project page schat.

License

The source code is released under:

MIT License

If you think the Android project schat 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 data;
/*from ww  w  .  ja v a  2  s .  c o m*/
import crypto.Cryptography;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * @author Gary Ye
 * @version 12/1/13
 */
public class KeyPairManager {
    public static void outputBytesToFile(byte[] bytes, String filename){
        try(FileOutputStream fos = new FileOutputStream(filename)){
            fos.write(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static byte[] readBytesFromFile(String filename){
        Path path = Paths.get(filename);
        byte[] data = null;
        try {
            if(Files.exists(path))
                data = Files.readAllBytes(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return data;
    }
    public static PublicKey readPublicKey(String publicKeyFile){
        return Cryptography.getPublicKeyFromBytes(readBytesFromFile(publicKeyFile));
    }
    public static PrivateKey readPrivateKey(String privateKeyFile){
        return Cryptography.getPrivateKeyFromBytes(readBytesFromFile(privateKeyFile));
    }
    public static KeyPair readKeyPair(String publicKeyFile, String privateKeyFile){
        return new KeyPair(readPublicKey(publicKeyFile), readPrivateKey(privateKeyFile));
    }
    public static void main(String[] args){
        KeyPair keyPair = Cryptography.gen_asymm_key();
        outputBytesToFile(keyPair.getPublic().getEncoded(), "public.key");
        outputBytesToFile(keyPair.getPrivate().getEncoded(), "private.key");
    }
}




Java Source Code List

.ServerMain.java
com.activities.Activity_Chat.java
com.activities.Activity_ContactList.java
com.activities.ContactView.java
com.data.AddContact.java
com.data.AndroidSQLManager.java
com.data.ApplicationUser.java
com.data.ChatAdapter.java
com.data.ChatArrayList.java
com.data.MySQLiteHelper.java
com.security.AndroidKeyPairManager.java
com.security.PRNGFixes.java
com.services.MessageService.java
crypto.CryptoConstants.java
crypto.Cryptography.java
crypto.Envelope.java
crypto.SecureMessage.java
crypto.TestCrypto.java
data.ChatMessage.java
data.Content.java
data.DatabaseManager.java
data.KeyPairManager.java
data.Message.java
data.SQLiteManager.java
data.User.java
data.contents.ChatContent.java
data.contents.LoginSuccess.java
data.contents.Login.java
data.contents.PublicKeyRequest.java
data.contents.PublicKeyResponse.java
data.contents.Registration.java
networking.SChatClientListener.java
networking.SChatClientWriter.java
networking.SChatClient.java
networking.SChatServerThread.java
networking.SChatServer.java