// Path: SecureJavaChannel/src/main/java/Properties/Properties.java
// public class Properties {
// 
//     //socket properties
//     public static final int ConnectionPort = 5555;
//     public static final int MaxConnections = 100;
//     public static final int timeout = 10 * 1000;
// 
//     public static final String END_PROTOCOL = "EndSession";
//     //Put your message which you want taken from Server
//    public static final String PlainText_UTF8 = "Hello Client Send me again Enrypted Message";
//     
//     //encryption properties  
//    
// 
//     //for more info check https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
//     //g^x mod p 
//     //However, its very unlikely that anyone else listening on the channel 
//     //can calculate the key, since the calculation of discrete logarithms under 
//     //field arithmetic is very hard (see Galois Fields)
//     //Prime numbers machine generator 
//     public static final String exponent = "95632573769194905177488615436919317766582673020891665265323677789504596581977";
//     public static final String modulus = "81554351438297688582888558141846154981885664956959015742153749206820791432251";
// 
//     public static final String AES_PROVIDER = "AES";
//     public static final String AES_ALGORITHM = "AES/CBC/PKCS7Padding";
// 
//     //Rsa needed
//     public static final String RSA_ALGORITHM = "RSA";
//     public static final String RSA_CRYPTO_ALGORITHM = "RSA/ECB/PKCS1Padding";
//     public static final String RSA_Provider = "BC";
// 
//     //store_keys
//     public static final String PUBLIC_KEY_FILE = "Public.key";
//     public static final String PRIVATE_KEY_FILE = "Private.key";
// 
//     //Encodes values
//     public static final String CHAR_ENCODING = "UTF-8";
//     public static final String HashingAlgorithm = "md5";
// 
//     //keysizes-length
//     public static final int KeySizeLength = 16;
//     public static final int RSA_KEYSIZE = 1024;
//     
//      //HmacAlgProvider hash Function
//      public static final String HmacAlgProv="HmacSHA256";
//     //Rsa Integrity Signature
//      public static final String Signature="SHA256withRSA";
// }


import Properties.Properties;
import java.security.PrivateKey;
import java.security.PublicKey;
import javax.crypto.Cipher;
import org.apache.commons.codec.binary.Base64;
package org.RSA_Encryption;


public class RSA_Encryption {

    public static String RsaEecrypt(PublicKey pubKey, String plainText) throws Exception {
        byte[] plainBytes = plainText.getBytes(Properties.CHAR_ENCODING);
        Cipher cipher = Cipher.getInstance(Properties.RSA_CRYPTO_ALGORITHM, Properties.RSA_Provider);

        byte[] iv = new byte[16];
        cipher.init(Cipher.ENCRYPT_MODE, pubKey);

        byte[] encrypted = cipher.doFinal(plainBytes);
        String encryptedString = new String(Base64.encodeBase64(encrypted));

        return encryptedString;
    }

    public static String RsaDecrypt(PrivateKey privateKey, String EncryptedText) throws Exception {
        byte[] plainBytes = Base64.decodeBase64(EncryptedText.getBytes(Properties.CHAR_ENCODING));
        byte[] iv = new byte[16]; // initialization vector with all 0

// Path: SecureJavaChannel/src/main/java/Properties/Properties.java
// public class Properties {
// 
//     //socket properties
//     public static final int ConnectionPort = 5555;
//     public static final int MaxConnections = 100;
//     public static final int timeout = 10 * 1000;
// 
//     public static final String END_PROTOCOL = "EndSession";
//     //Put your message which you want taken from Server
//    public static final String PlainText_UTF8 = "Hello Client Send me again Enrypted Message";
//     
//     //encryption properties  
//    
// 
//     //for more info check https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
//     //g^x mod p 
//     //However, its very unlikely that anyone else listening on the channel 
//     //can calculate the key, since the calculation of discrete logarithms under 
//     //field arithmetic is very hard (see Galois Fields)
//     //Prime numbers machine generator 
//     public static final String exponent = "95632573769194905177488615436919317766582673020891665265323677789504596581977";
//     public static final String modulus = "81554351438297688582888558141846154981885664956959015742153749206820791432251";
// 
//     public static final String AES_PROVIDER = "AES";
//     public static final String AES_ALGORITHM = "AES/CBC/PKCS7Padding";
// 
//     //Rsa needed
//     public static final String RSA_ALGORITHM = "RSA";
//     public static final String RSA_CRYPTO_ALGORITHM = "RSA/ECB/PKCS1Padding";
//     public static final String RSA_Provider = "BC";
// 
//     //store_keys
//     public static final String PUBLIC_KEY_FILE = "Public.key";
//     public static final String PRIVATE_KEY_FILE = "Private.key";
// 
//     //Encodes values
//     public static final String CHAR_ENCODING = "UTF-8";
//     public static final String HashingAlgorithm = "md5";
// 
//     //keysizes-length
//     public static final int KeySizeLength = 16;
//     public static final int RSA_KEYSIZE = 1024;
//     
//      //HmacAlgProvider hash Function
//      public static final String HmacAlgProv="HmacSHA256";
//     //Rsa Integrity Signature
//      public static final String Signature="SHA256withRSA";
// }


// Path: SecureJavaChannel/src/main/java/org/RSA_Encryption/RSA_Encryption.java
import Properties.Properties;
import java.security.PrivateKey;
import java.security.PublicKey;
import javax.crypto.Cipher;
import org.apache.commons.codec.binary.Base64;

package org.RSA_Encryption;


public class RSA_Encryption {

    public static String RsaEecrypt(PublicKey pubKey, String plainText) throws Exception {
        byte[] plainBytes = plainText.getBytes(Properties.CHAR_ENCODING);
        Cipher cipher = Cipher.getInstance(Properties.RSA_CRYPTO_ALGORITHM, Properties.RSA_Provider);

        byte[] iv = new byte[16];
        cipher.init(Cipher.ENCRYPT_MODE, pubKey);

        byte[] encrypted = cipher.doFinal(plainBytes);
        String encryptedString = new String(Base64.encodeBase64(encrypted));

        return encryptedString;
    }

    public static String RsaDecrypt(PrivateKey privateKey, String EncryptedText) throws Exception {
        byte[] plainBytes = Base64.decodeBase64(EncryptedText.getBytes(Properties.CHAR_ENCODING));
        byte[] iv = new byte[16]; // initialization vector with all 0

        Cipher cipher = Cipher.getInstance(Properties.RSA_CRYPTO_ALGORITHM, Properties.RSA_Provider);