test.java
来自「加密解密程序,实现了加密解密功能,无解密密码」· Java 代码 · 共 70 行
JAVA
70 行
import java.io.*;
public class Test
{
public static void main(String[] args)
{
System.out.print("Encode follow string: ");
String a=MyInput.readString();
byte[] b=new byte[a.length()];
b=a.getBytes();
File tempfile=new File("temp.dat");
// encode output
try
{
FileOutputStream out=new FileOutputStream(tempfile);
EncryptOutputStream Eout=new EncryptOutputStream(out);
Eout.ewrite(b);
System.out.println("Save successfully!");
}
catch (IOException ex)
{
System.out.println(ex);
}
//non-decode input
byte[] read=new byte[a.length()];
try
{
System.out.print("use FileInputStream to open file: ");
int temp;
FileInputStream in=new FileInputStream(tempfile);
temp=in.read(read);
String str=new String(read);
if(temp!=-1)
System.out.println(str);
in.close();
}
catch (IOException ex)
{
System.out.println(ex);
}
//decode input
try
{ System.out.print("use DecryptInputStream to open file: ");
byte[] nread=new byte[a.length()];
int temp;
FileInputStream din=new FileInputStream(tempfile);
DecryptInputStream Di=new DecryptInputStream(din);
temp=Di.dread(nread);
String nstr=new String(nread);
if(temp!=-1)
System.out.println(nstr);
din.close();
}
catch (IOException ex)
{
System.out.println(ex);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?