glenn
glenn

Reputation: 3

How to Export Runnable Jar from Eclipse with external NON text file. Encrypt & Decrypt Certificates in src folder

I have tried everywhere and looked at almost everything on the web. The code functions nicely in Eclipse, but will not in a runnable jar exported because it gives a file not found exception for the certificate public.der. All the other files are made and kept in the file of the users choice, but this application requires that the public and private key files be kept inside. Any ideas to be able to export the certificate files as a resource? Everything else works perfectly. I have tried as inputstream with getResource(), and with other made folders in eclipse. The filepath specified is input from the user for the directory and file they would like to encrypt. The secure data files are made and deposited in the same directory the user inputs. The public.der is the public key certificate and will not typically be on the user's computer. How do I export it with the jar. I have tried normal exports, exports with the src folder, exports with an added folder to the class directory, exports after adding the folder to the properties of the class build path. Nothing so far works.

public static void Encryption(String Filepath) throws GeneralSecurityException, IOException{

CryptoFunction secure = new CryptoFunction();

   // user inputted filepath
   String fullfilepath = Filepath;
   String filepath = "";

   // Encrypt code
   File originalFile = new File(fullfilepath);

   // File path for secure data files
   filepath = originalFile.getParent();

   File encryptedaessavekeyFile = new File(filepath + "/EncryptedAESSaveKeyFile.data");
   File encrypteddataFile = new File(filepath + "/EncryptedDataFile.data");
   File publicKeyData = new File("src/public.der");

   // create AES key
   secure.makeKey();

   // save AES key using public key
   secure.saveKey(encryptedaessavekeyFile, publicKeyData);

   // save original file securely 
   secure.encrypt(originalFile, encrypteddataFile); 

}

I will give full code, but only to those who ask and want to help.

Upvotes: 0

Views: 480

Answers (1)

AdventureTimeOH
AdventureTimeOH

Reputation: 1

This might not help you but you could always make a part of the program that reads a string your Encrypting and makes it encrypted with your own language and save it to a properties file then do it vis-versa to Decrypt

Example:

public String[] encryption(String[] stringList, String stringToEncrypt, /*(other strings)*/)

    String[stringList.length] encrytion;

    for(int amountOfStringsToEncrypt = 0; amountOfString <= stringList; amountOfStringsToEncrypt++){

        StringBuilder encryptedString = new StringBuilder();
        char[stringList.length] toEncrypt;

        for(int encrypt = 0; encrypt <= string.length;encrypt++){
            toEncrypt[encrypt] = string.charAt(encrypt)
        }

        for(int encrypt = 0; encrypt <= toEcrypt.length; encrypt++){
            if(toEncrypt[encrypt].equals(" "){
                toEncrypt[encrypt] == "%_%");
            }
            else if(toEncrypt[encrypt].equals("a"){
                toEncrypt[encrypt] == "{");
            }
            else if(toEncrypt[encrypt].equals("b"){
                toEncrypt[encrypt] == "/");
            }
            else if(toEncrypt[encrypt].equals("c"){
                toEncrypt[encrypt] == "?");
            }
            else if(toEncrypt[encrypt].equals("d"){
                toEncrypt[encrypt] == "&%#");
            }
            //ect....

            encryptedString.add(toEncrypt[encrypt]);
        }

        encryption[amountOfStringsToEncrypt] = encryptedString;
    }

        return encrytption;
}

Hope this helps! Might be a few errors because I was coding off the top of my head.

Upvotes: 0

Related Questions