welcomeriver
发贴: 9
积分: 0
|
于 2005-03-17 15:04
import java.io.*; import java.security.*; import javax.crypto.*;
public class StreamIn { public static void main(String[] args) throws Exception { FileInputStream f = new FileInputStream("key1.dat"); ObjectInputStream b = new ObjectInputStream; Key k = (Key)b.readObject();
Cipher cp = Cipher.getInstance("DESede"); cp.init(Cipher.ENCRYPT_MODE, k);
FileInputStream in = new FileInputStream("test1.txt"); CipherInputStream cin = new CipherInputStream(in, cp); int num = in.available(); byte ptext[] = new byte[num]; cin.read(ptext);
FileOutputStream out = new FileOutputStream("test2.txt"); Cipher cp1 = Cipher.getInstance("DESede"); cp1.init(Cipher.DECRYPT_MODE, k); CipherOutputStream cout = new CipherOutputStream(out, cp1);
cout.write(ptext);
cout.close(); out.close(); in.close(); cin.close(); } }
为什么输出文件 test2.txt 总是空的呢?
|