home *** CD-ROM | disk | FTP | other *** search
- package java.security;
-
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
-
- public final class SignedObject implements Serializable {
- private byte[] content;
- private byte[] signature;
- private String thealgorithm;
-
- public SignedObject(Serializable var1, PrivateKey var2, Signature var3) throws IOException, InvalidKeyException, SignatureException {
- ByteArrayOutputStream var4 = new ByteArrayOutputStream();
- ObjectOutputStream var5 = new ObjectOutputStream(var4);
- var5.writeObject(var1);
- var5.flush();
- var5.close();
- this.content = var4.toByteArray();
- var4.close();
- this.sign(var2, var3);
- }
-
- public Object getObject() throws IOException, ClassNotFoundException {
- ByteArrayInputStream var1 = new ByteArrayInputStream(this.content);
- ObjectInputStream var2 = new ObjectInputStream(var1);
- Object var3 = var2.readObject();
- var1.close();
- var2.close();
- return var3;
- }
-
- public byte[] getSignature() {
- byte[] var1 = (byte[])this.signature.clone();
- return var1;
- }
-
- public String getAlgorithm() {
- return this.thealgorithm;
- }
-
- public boolean verify(PublicKey var1, Signature var2) throws InvalidKeyException, SignatureException {
- var2.initVerify(var1);
- var2.update(this.content);
- return var2.verify(this.signature);
- }
-
- private void sign(PrivateKey var1, Signature var2) throws InvalidKeyException, SignatureException {
- var2.initSign(var1);
- var2.update(this.content);
- this.signature = var2.sign();
- this.thealgorithm = var2.getAlgorithm();
- }
-
- private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- var1.defaultReadObject();
- this.content = (byte[])this.content.clone();
- this.signature = (byte[])this.signature.clone();
- }
- }
-