我在序列化 cipherinputstream 对象时遇到问题。每当我尝试这样做时,我总是会遇到此异常,这是我的代码片段
public class Crypto implements java.io.Serializable
{
public Crypto(String filename)
{
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
SecretKeySpec secretkey = new SecretKeySpec(key(), "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretkey);
CipherInputStream cipt = new CipherInputStream(new FileInputStream(new File(filename)), cipher)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream obj = null;
try
{
obj = new ObjectOutputStream(baos);
obj.writeObject(cipt);
byte[] bv = baos.toByteArray();
System.out.println(bv);
}
catch(Exception b)
{
b.printStackTrace();
}
finally
{
obj.close();
baos.close();
}
}
}
例外:
java.io.NotSerializableException: javax.crypto.CipherInputStream.
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
谁能帮我做到这一点。我的目标是将 cipherinputstream 对象转换为字节或字节数组。