-1

我在序列化 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 对象转换为字节或字节数组。

4

1 回答 1

-1

可能 U 不会实现可序列化的标记类。假设 A 类是 U 需要序列化的类,则:

class A implements serializable {

  //class variables and methods


}
于 2013-07-25T10:23:03.010 回答