Ejemplo n.º 1
0
  public JCEECPrivateKey(
      String algorithm,
      ECPrivateKeyParameters params,
      JCEECPublicKey pubKey,
      ECParameterSpec spec) {
    ECDomainParameters dp = params.getParameters();

    this.algorithm = algorithm;
    this.d = params.getD();

    if (spec == null) {
      EllipticCurve ellipticCurve = EC5Util.convertCurve(dp.getCurve(), dp.getSeed());

      this.ecSpec =
          new ECParameterSpec(
              ellipticCurve,
              new ECPoint(dp.getG().getX().toBigInteger(), dp.getG().getY().toBigInteger()),
              dp.getN(),
              dp.getH().intValue());
    } else {
      this.ecSpec = spec;
    }

    publicKey = getPublicKeyDetails(pubKey);
  }
Ejemplo n.º 2
0
  private void populateFromPrivKeyInfo(PrivateKeyInfo info) {
    X962Parameters params = new X962Parameters((DERObject) info.getAlgorithmId().getParameters());

    if (params.isNamedCurve()) {
      DERObjectIdentifier oid = (DERObjectIdentifier) params.getParameters();
      X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);

      if (ecP == null) // GOST Curve
      {
        ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
        EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());

        ecSpec =
            new ECNamedCurveSpec(
                ECGOST3410NamedCurves.getName(oid),
                ellipticCurve,
                new ECPoint(
                    gParam.getG().getX().toBigInteger(), gParam.getG().getY().toBigInteger()),
                gParam.getN(),
                gParam.getH());
      } else {
        EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());

        ecSpec =
            new ECNamedCurveSpec(
                ECUtil.getCurveName(oid),
                ellipticCurve,
                new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()),
                ecP.getN(),
                ecP.getH());
      }
    } else if (params.isImplicitlyCA()) {
      ecSpec = null;
    } else {
      X9ECParameters ecP = new X9ECParameters((ASN1Sequence) params.getParameters());
      EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());

      this.ecSpec =
          new ECParameterSpec(
              ellipticCurve,
              new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()),
              ecP.getN(),
              ecP.getH().intValue());
    }

    if (info.getPrivateKey() instanceof DERInteger) {
      DERInteger derD = (DERInteger) info.getPrivateKey();

      this.d = derD.getValue();
    } else {
      ECPrivateKeyStructure ec = new ECPrivateKeyStructure((ASN1Sequence) info.getPrivateKey());

      this.d = ec.getKey();
      this.publicKey = ec.getPublicKey();
    }
  }