我到处尝试过,几乎看了网络上的所有内容。该代码在 Eclipse 中运行良好,但不会在导出的可运行 jar 中运行,因为它为证书 public.der 提供了找不到文件异常。所有其他文件都制作并保存在用户选择的文件中,但此应用程序要求公钥和私钥文件保存在其中。能够将证书文件导出为资源的任何想法?其他一切都很完美。我已经尝试过使用 getResource() 和 eclipse 中的其他文件夹作为输入流。指定的文件路径是用户对要加密的目录和文件的输入。安全数据文件制作并存放在用户输入的同一目录中。public.der 是公钥证书,通常不会位于用户的计算机上。如何使用罐子导出它。我已经尝试了普通导出,使用 src 文件夹导出,使用添加到类目录的文件夹导出,将文件夹添加到类构建路径的属性后导出。到目前为止没有任何效果。
public static void Encryption(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;
}
希望这有帮助!可能是一些错误,因为我正在编码我的头顶。