home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / security / SignedObject.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.9 KB  |  63 lines

  1. package java.security;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.ByteArrayOutputStream;
  5. import java.io.IOException;
  6. import java.io.ObjectInputStream;
  7. import java.io.ObjectOutputStream;
  8. import java.io.Serializable;
  9.  
  10. public final class SignedObject implements Serializable {
  11.    private byte[] content;
  12.    private byte[] signature;
  13.    private String thealgorithm;
  14.  
  15.    public SignedObject(Serializable var1, PrivateKey var2, Signature var3) throws IOException, InvalidKeyException, SignatureException {
  16.       ByteArrayOutputStream var4 = new ByteArrayOutputStream();
  17.       ObjectOutputStream var5 = new ObjectOutputStream(var4);
  18.       var5.writeObject(var1);
  19.       var5.flush();
  20.       var5.close();
  21.       this.content = var4.toByteArray();
  22.       var4.close();
  23.       this.sign(var2, var3);
  24.    }
  25.  
  26.    public Object getObject() throws IOException, ClassNotFoundException {
  27.       ByteArrayInputStream var1 = new ByteArrayInputStream(this.content);
  28.       ObjectInputStream var2 = new ObjectInputStream(var1);
  29.       Object var3 = var2.readObject();
  30.       var1.close();
  31.       var2.close();
  32.       return var3;
  33.    }
  34.  
  35.    public byte[] getSignature() {
  36.       byte[] var1 = (byte[])this.signature.clone();
  37.       return var1;
  38.    }
  39.  
  40.    public String getAlgorithm() {
  41.       return this.thealgorithm;
  42.    }
  43.  
  44.    public boolean verify(PublicKey var1, Signature var2) throws InvalidKeyException, SignatureException {
  45.       var2.initVerify(var1);
  46.       var2.update(this.content);
  47.       return var2.verify(this.signature);
  48.    }
  49.  
  50.    private void sign(PrivateKey var1, Signature var2) throws InvalidKeyException, SignatureException {
  51.       var2.initSign(var1);
  52.       var2.update(this.content);
  53.       this.signature = var2.sign();
  54.       this.thealgorithm = var2.getAlgorithm();
  55.    }
  56.  
  57.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  58.       var1.defaultReadObject();
  59.       this.content = (byte[])this.content.clone();
  60.       this.signature = (byte[])this.signature.clone();
  61.    }
  62. }
  63.