Exemplo n.º 1
0
 /** Construct a key from its components. Used by the ECKeyFactory and SunPKCS11. */
 public ECPublicKeyImpl(ECPoint w, ECParameterSpec params) throws InvalidKeyException {
   this.w = w;
   this.params = params;
   // generate the encoding
   algid = new AlgorithmId(AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params));
   key = ECParameters.encodePoint(w, params.getCurve());
 }
Exemplo n.º 2
0
 /** Parse the key. Called by X509Key. */
 protected void parseKeyBits() throws InvalidKeyException {
   try {
     AlgorithmParameters algParams = this.algid.getParameters();
     params = algParams.getParameterSpec(ECParameterSpec.class);
     w = ECParameters.decodePoint(key, params.getCurve());
   } catch (IOException e) {
     throw new InvalidKeyException("Invalid EC key", e);
   } catch (InvalidParameterSpecException e) {
     throw new InvalidKeyException("Invalid EC key", e);
   }
 }
Exemplo n.º 3
0
 /** Construct a key from its components. Used by the KeyFactory. */
 ECPrivateKeyImpl(BigInteger s, ECParameterSpec params) throws InvalidKeyException {
   this.s = s;
   this.params = params;
   // generate the encoding
   algid = new AlgorithmId(AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params));
   try {
     DerOutputStream out = new DerOutputStream();
     out.putInteger(1); // version 1
     byte[] privBytes = ECUtil.trimZeroes(s.toByteArray());
     out.putOctetString(privBytes);
     DerValue val = new DerValue(DerValue.tag_Sequence, out.toByteArray());
     key = val.toByteArray();
   } catch (IOException exc) {
     // should never occur
     throw new InvalidKeyException(exc);
   }
 }