Java 无法解码.txt文件中的base64
如何在Java中解密或读取base64Java 无法解码.txt文件中的base64,java,loops,while-loop,base64,Java,Loops,While Loop,Base64,如何在Java中解密或读取base64.txt文件 import java.io.*; import java.util.*; public class BaseDec { public static void main (String[]args)throws IOException{ System.out.print("Enter the file name with extension:"); Scanner sc = new Scanner(
.txt
文件
import java.io.*;
import java.util.*;
public class BaseDec {
public static void main (String[]args)throws IOException{
System.out.print("Enter the file name with extension:");
Scanner sc = new Scanner(System.in);
File GuionFile = new File(sc.nextLine());
sc = new Scanner(File);
String GuionLine = sc.nextLine();
byte[] decodedArr = Base64.getDecoder().decode(File);
String decodedText = new String(decodedArr);
System.out.println(decodedText);
sc.close();
}
}
此代码段在JShell中工作:
import org.codehaus.plexus.util.Base64;
import java.io.File;
import java.nio.file.Files;
File file = new File("base64test.txt");
System.out.println(new String(Base64.decodeBase64(Files.readAllBytes(file.toPath()))));
如果您使用
Base64.getEncoder()
编码,则可能使用Base64.getEncoder()
。你试过什么?它在哪里失败了?注意:base64不是一种加密格式,所以解码它不是所谓的“解密”,只是“解码”。将“机密”信息存储在base64中增加的安全性非常小-它只能确保不想看到机密信息的人不会意外地看到它。我不知道怎么做o.oi更新了我的代码请帮助