我有一个程序正在加密一个文本文件,并保存编码的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分钟,直到我可以,哈哈 –