示例#1
0
 protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random)
     throws InvalidKeyException, InvalidAlgorithmParameterException {
   if (params != null && params.getAlgorithm().equals("RC2")) {
     try {
       RC2ParameterSpec rc2Params = params.getParameterSpec(RC2ParameterSpec.class);
       engineInit(opmode, key, rc2Params, random);
     } catch (InvalidParameterSpecException ipse) {
       throw new InvalidAlgorithmParameterException("Wrong parameter type: RC2 expected");
     }
   } else {
     embeddedCipher.initEffectiveKeyBits(0);
     core.init(opmode, key, params, random);
   }
 }
示例#2
0
 /** Parse the key. Called by PKCS8Key. */
 protected void parseKeyBits() throws InvalidKeyException {
   try {
     DerInputStream in = new DerInputStream(key);
     DerValue derValue = in.getDerValue();
     if (derValue.tag != DerValue.tag_Sequence) {
       throw new IOException("Not a SEQUENCE");
     }
     DerInputStream data = derValue.data;
     int version = data.getInteger();
     if (version != 1) {
       throw new IOException("Version must be 1");
     }
     byte[] privData = data.getOctetString();
     s = new BigInteger(1, privData);
     while (data.available() != 0) {
       DerValue value = data.getDerValue();
       if (value.isContextSpecific((byte) 0)) {
         // ignore for now
       } else if (value.isContextSpecific((byte) 1)) {
         // ignore for now
       } else {
         throw new InvalidKeyException("Unexpected value: " + value);
       }
     }
     AlgorithmParameters algParams = this.algid.getParameters();
     if (algParams == null) {
       throw new InvalidKeyException(
           "EC domain parameters must be " + "encoded in the algorithm identifier");
     }
     params = algParams.getParameterSpec(ECParameterSpec.class);
   } catch (IOException e) {
     throw new InvalidKeyException("Invalid EC private key", e);
   } catch (InvalidParameterSpecException e) {
     throw new InvalidKeyException("Invalid EC private key", e);
   }
 }