<commit_before>package com.jacobmdavison.computersmsserver;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.Base64;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyAgreement;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.SecretKeySpec;

/**
 * Uses Diffie Hellman to generate shared AES key, then encrypts/decrypts strings
 * Created by jacobdavidson on 8/27/15.
 */
public class DiffieHellmanModule {

    private static final int AES_KEY_SIZE = 128;
    private KeyPairGenerator keyPairGenerator;
    private PublicKey publicKey;
    private PrivateKey privateKey;
    private SecretKey secretKey;
    private boolean isConnected = false;

    public DiffieHellmanModule() {
        // Init the KeyPairGenerator
        try {
        	//int bitLength = 1024;
            //SecureRandom rnd = new SecureRandom();
            //BigInteger p = BigInteger.probablePrime(bitLength, rnd);
            //BigInteger g = BigInteger.probablePrime(bitLength, rnd);
            DHParameterSpec dhParameterSpec = new DHParameterSpec(skip1024Modulus, skip1024Base);
            keyPairGenerator = KeyPairGenerator.getInstance("DH");
            //keyPairGenerator.initialize(1024);
            keyPairGenerator.initialize(dhParameterSpec);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } 
        
        
        catch (InvalidAlgorithmParameterException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        // Generate the Key Pairs
        KeyPair keyPair = keyPairGenerator.genKeyPair();

        publicKey = keyPair.getPublic();
        privateKey = keyPair.getPrivate();


    }

    public PublicKey getPublicKey() {
        return publicKey;
    }
    
    public SecretKey getSecretKey() {
    	return secretKey;
    }

    // Set the public key and generate the shared AES key
    public void generateSecretKey(PublicKey receivedPublicKey, boolean lastPhase) {

        try {<commit_msg>Removed some comments<commit_after>package com.jacobmdavison.computersmsserver;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.Base64;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyAgreement;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.SecretKeySpec;

/**
 * Uses Diffie Hellman to generate shared AES key, then encrypts/decrypts strings
 * Created by jacobdavidson on 8/27/15.
 */
public class DiffieHellmanModule {

    private static final int AES_KEY_SIZE = 128;
    private KeyPairGenerator keyPairGenerator;
    private PublicKey publicKey;
    private PrivateKey privateKey;
    private SecretKey secretKey;
    private boolean isConnected = false;

    public DiffieHellmanModule() {
        // Init the KeyPairGenerator
        try {
            DHParameterSpec dhParameterSpec = new DHParameterSpec(skip1024Modulus, skip1024Base);
            keyPairGenerator = KeyPairGenerator.getInstance("DH");
            keyPairGenerator.initialize(dhParameterSpec);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } 
        
        
        catch (InvalidAlgorithmParameterException e) {
			e.printStackTrace();
		}

        // Generate the Key Pairs
        KeyPair keyPair = keyPairGenerator.genKeyPair();

        publicKey = keyPair.getPublic();
        privateKey = keyPair.getPrivate();


    }

    public PublicKey getPublicKey() {
        return publicKey;
    }
    
    public SecretKey getSecretKey() {
    	return secretKey;
    }

    // Set the public key and generate the shared AES key
    public void generateSecretKey(PublicKey receivedPublicKey, boolean lastPhase) {

        try {
{'fraction_non_alphanumeric': 0.07601600336913035, 'fraction_numerical': 0.009265108443882923, 'mean_word_length': 3.506641366223909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7154173', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1246, 'n_words': 308}