Example #1
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);
   }
 }