-1
我在序列化cipherinputstream对象时遇到问题。我总是得到这个异常每当我试图做到这一点,这里是我的代码片段如何序列化和反序列化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对象转换为字节或字节数组。
U是否实现了序列化? –
你想实现什么?你想写密码本身还是真的是对象'CipherInputStream'? –
对象CipherInputStream –