我已经制作了加密和解密类,现在我想测试它。 加密器shold采用som文本并将其加密为.txt文件。但它不起作用。
public class Encryption extends FilterWriter{
private static int INKREMENT = 3;
protected Encryption(Writer arg0) {
super(arg0);
}
public void write(String str, int off, int len) throws IOException{
String result = str.substring(0,off);
for(int i = off; i<len+off; i++){
result += (char) ((int) str.charAt(i)+ INKREMENT);
}
result += str.substring(off+len);
out.write(result);
}
public void write(int c) throws IOException{
out.write(c + INKREMENT);
}
public void write(char[] cbuf, int off, int len) throws IOException{
for(int i = off; i < len + off; i++){
cbuf[i] = (char)((int) cbuf[i] + INKREMENT);
}
out.write(cbuf,off,len);
}
}
我的考试?我不知道写什么来获取字符串加密并保存在text.txt文件中
Writer out = new Encryption(new BufferedWriter(new FileWriter("text.txt")));
答案 0 :(得分:0)
请参阅javax.crypto.CipherOutputStream
。它已经完成了。