簡體   English   中英

如何使用外部NON文本文件從Eclipse導出可運行Jar。 加密和解密src文件夾中的證書

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

我到處都嘗試過,幾乎瀏覽了網上的所有內容。 該代碼在Eclipse中運行良好,但在導出的可運行jar中則無法運行,因為它為證書public.der提供了未找到的文件異常。 所有其他文件均已制作並保存在用戶選擇的文件中,但是此應用程序要求將公鑰和私鑰文件保存在其中。 有什么想法可以將證書文件導出為資源? 其他一切都完美運行。 我已經嘗試過使用getResource()和eclipse中的其他文件夾作為inputstream。 從用戶輸入他們想要加密的目錄和文件的指定文件路徑。 制作安全數據文件並將其存放在用戶輸入的同一目錄中。 public.der是公鑰證書,通常不會在用戶的計算機上。 如何將其與罐子一起導出。 我嘗試了正常的導出,使用src文件夾導出,使用添加的文件夾導出到類目錄,將文件夾添加到類構建路徑的屬性后導出。 到目前為止沒有任何工作。

公共靜態無效加密(String Filepath)拋出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); 

}

我將提供完整的代碼,但僅提供給那些要求和想要幫助的人。

這可能對您沒有幫助,但是您始終可以成為程序的一部分,該程序會讀取您的加密字符串,並使用您自己的語言對其進行加密,然后將其保存到屬性文件中,然后反之以解密

例:

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;
}

希望這可以幫助! 可能有一些錯誤,因為我頭頂上正在編碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM