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 / Signature$CipherAdapter.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.1 KB  |  83 lines

  1. package java.security;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4. import java.util.Arrays;
  5. import javax.crypto.BadPaddingException;
  6. import javax.crypto.Cipher;
  7. import javax.crypto.IllegalBlockSizeException;
  8.  
  9. class Signature$CipherAdapter extends SignatureSpi {
  10.    private final Cipher cipher;
  11.    private ByteArrayOutputStream data;
  12.  
  13.    Signature$CipherAdapter(Cipher var1) {
  14.       this.cipher = var1;
  15.    }
  16.  
  17.    protected void engineInitVerify(PublicKey var1) throws InvalidKeyException {
  18.       this.cipher.init(2, var1);
  19.       if (this.data == null) {
  20.          this.data = new ByteArrayOutputStream(128);
  21.       } else {
  22.          this.data.reset();
  23.       }
  24.  
  25.    }
  26.  
  27.    protected void engineInitSign(PrivateKey var1) throws InvalidKeyException {
  28.       this.cipher.init(1, var1);
  29.       this.data = null;
  30.    }
  31.  
  32.    protected void engineInitSign(PrivateKey var1, SecureRandom var2) throws InvalidKeyException {
  33.       this.cipher.init(1, var1, var2);
  34.       this.data = null;
  35.    }
  36.  
  37.    protected void engineUpdate(byte var1) throws SignatureException {
  38.       this.engineUpdate(new byte[]{var1}, 0, 1);
  39.    }
  40.  
  41.    protected void engineUpdate(byte[] var1, int var2, int var3) throws SignatureException {
  42.       if (this.data != null) {
  43.          this.data.write(var1, var2, var3);
  44.       } else {
  45.          byte[] var4 = this.cipher.update(var1, var2, var3);
  46.          if (var4 != null && var4.length != 0) {
  47.             throw new SignatureException("Cipher unexpectedly returned data");
  48.          }
  49.       }
  50.    }
  51.  
  52.    protected byte[] engineSign() throws SignatureException {
  53.       try {
  54.          return this.cipher.doFinal();
  55.       } catch (IllegalBlockSizeException var2) {
  56.          throw new SignatureException("doFinal() failed", var2);
  57.       } catch (BadPaddingException var3) {
  58.          throw new SignatureException("doFinal() failed", var3);
  59.       }
  60.    }
  61.  
  62.    protected boolean engineVerify(byte[] var1) throws SignatureException {
  63.       try {
  64.          byte[] var2 = this.cipher.doFinal(var1);
  65.          byte[] var3 = this.data.toByteArray();
  66.          this.data.reset();
  67.          return Arrays.equals(var2, var3);
  68.       } catch (BadPaddingException var4) {
  69.          return false;
  70.       } catch (IllegalBlockSizeException var5) {
  71.          throw new SignatureException("doFinal() failed", var5);
  72.       }
  73.    }
  74.  
  75.    protected void engineSetParameter(String var1, Object var2) throws InvalidParameterException {
  76.       throw new InvalidParameterException("Parameters not supported");
  77.    }
  78.  
  79.    protected Object engineGetParameter(String var1) throws InvalidParameterException {
  80.       throw new InvalidParameterException("Parameters not supported");
  81.    }
  82. }
  83.