我有一個程序正在加密一個文本文件,並保存編碼的txt和密鑰seperatly。現在我試着編寫使用密鑰解密文件的解密程序。我讀了鑰匙,但似乎我不能像這樣使用它。有沒有人對我有任何建議,或者甚至不可能這樣做?java - 用外部密鑰解密文本文件
public class decrypt {
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException {
try {
File fileDir = new File("C:/xxx/key.txt");
BufferedReader in = new BufferedReader(
new InputStreamReader(new FileInputStream(fileDir), "UTF-8"));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
in.close();
}catch (UnsupportedEncodingException e){
System.out.println(e.getMessage());
}catch (IOException e){
System.out.println(e.getMessage());
}catch (Exception e){
System.out.println(e.getMessage());
}
byte[] decodedKey = Base64.getDecoder().decode(str);
SecretKey originalKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES");
}
}
謝謝你的工作! –
很高興我能幫到你。你現在可以接受我的答案,哈哈。 – mumpitz
我會,網站期待我再等3分鐘,直到我可以,哈哈 –