home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / security / KeyRep.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.2 KB  |  53 lines

  1. package java.security;
  2.  
  3. import java.io.NotSerializableException;
  4. import java.io.ObjectStreamException;
  5. import java.io.Serializable;
  6. import java.security.spec.PKCS8EncodedKeySpec;
  7. import java.security.spec.X509EncodedKeySpec;
  8. import javax.crypto.spec.SecretKeySpec;
  9.  
  10. public class KeyRep implements Serializable {
  11.    private static final long serialVersionUID = -4757683898830641853L;
  12.    private static final String PKCS8 = "PKCS#8";
  13.    private static final String X509 = "X.509";
  14.    private static final String RAW = "RAW";
  15.    private Type type;
  16.    private String algorithm;
  17.    private String format;
  18.    private byte[] encoded;
  19.  
  20.    public KeyRep(Type var1, String var2, String var3, byte[] var4) {
  21.       if (var1 != null && var2 != null && var3 != null && var4 != null) {
  22.          this.type = var1;
  23.          this.algorithm = var2;
  24.          this.format = var3.toUpperCase();
  25.          this.encoded = (byte[])(([B)var4).clone();
  26.       } else {
  27.          throw new NullPointerException("invalid null input(s)");
  28.       }
  29.    }
  30.  
  31.    protected Object readResolve() throws ObjectStreamException {
  32.       try {
  33.          if (this.type == java.security.KeyRep.Type.SECRET && "RAW".equals(this.format)) {
  34.             return new SecretKeySpec(this.encoded, this.algorithm);
  35.          } else if (this.type == java.security.KeyRep.Type.PUBLIC && "X.509".equals(this.format)) {
  36.             KeyFactory var5 = KeyFactory.getInstance(this.algorithm);
  37.             return var5.generatePublic(new X509EncodedKeySpec(this.encoded));
  38.          } else if (this.type == java.security.KeyRep.Type.PRIVATE && "PKCS#8".equals(this.format)) {
  39.             KeyFactory var1 = KeyFactory.getInstance(this.algorithm);
  40.             return var1.generatePrivate(new PKCS8EncodedKeySpec(this.encoded));
  41.          } else {
  42.             throw new NotSerializableException("unrecognized type/format combination: " + this.type + "/" + this.format);
  43.          }
  44.       } catch (NotSerializableException var3) {
  45.          throw var3;
  46.       } catch (Exception var4) {
  47.          NotSerializableException var2 = new NotSerializableException("java.security.Key: [" + this.type + "] " + "[" + this.algorithm + "] " + "[" + this.format + "]");
  48.          var2.initCause(var4);
  49.          throw var2;
  50.       }
  51.    }
  52. }
  53.