Package java.security.spec

Examples of java.security.spec.ECParameterSpec


            return KeyPairProvider.SSH_DSS;
        } else if (key instanceof RSAKey) {
            return KeyPairProvider.SSH_RSA;
        } else if (key instanceof ECKey) {
            ECKey ecKey = (ECKey) key;
            ECParameterSpec ecSpec = ecKey.getParams();
            /*
             * TODO make this more robust by checking the actual parameters instead of
             * just the field size.
             */
            switch (ecSpec.getCurve().getField().getFieldSize()) {
                case 256:
                    return KeyPairProvider.ECDSA_SHA2_NISTP256;
                case 384:
                    return KeyPairProvider.ECDSA_SHA2_NISTP384;
                case 521:
View Full Code Here


                        && p1.getP().equals(p2.getP())
                        && p1.getQ().equals(p2.getQ());
        } else if (k1 instanceof ECPublicKey && k2 instanceof ECPublicKey) {
            ECPublicKey e1 = (ECPublicKey) k1;
            ECPublicKey e2 = (ECPublicKey) k2;
            ECParameterSpec p1 = e1.getParams();
            ECParameterSpec p2 = e2.getParams();
            return p1.getCofactor() == p2.getCofactor()
                        && p1.getOrder().equals(p2.getOrder())
                        && e1.getW().equals(e2.getW())
                        && p1.getGenerator().equals(p2.getGenerator())
                        && p1.getCurve().equals(p2.getCurve());
        } else if (k1 instanceof RSAPublicKey && k2 instanceof RSAPublicKey) {
            RSAPublicKey r1 = (RSAPublicKey) k1;
            RSAPublicKey r2 = (RSAPublicKey) k2;
            return r1.getModulus().equals(r2.getModulus())
                        && r1.getPublicExponent().equals(r2.getPublicExponent());
View Full Code Here

    public static PublicKey getECPublicKeyWithParams(final PublicKey pk, final String keySpec) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException {
      PublicKey ret = pk;
      if ( (pk instanceof PublicKeyEC) && (keySpec != null) ) {
        final PublicKeyEC pkec = (PublicKeyEC) pk;
        // The public key of IS and DV certificate do not have any parameters so we have to do some magic to get a complete EC public key
        final ECParameterSpec spec = pkec.getParams();
        if (spec == null) {
          // we did not have the parameter specs, lets create them because we know which curve we are using
          final org.bouncycastle.jce.spec.ECParameterSpec bcspec = ECNamedCurveTable.getParameterSpec(keySpec);
          final java.security.spec.ECPoint p = pkec.getW();
          final org.bouncycastle.math.ec.ECPoint ecp = EC5Util.convertPoint(bcspec.getCurve(), p, false);
View Full Code Here

    public static PublicKey getECPublicKeyWithParams(final PublicKey pk, final PublicKey pkwithparams) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException {
      PublicKey ret = pk;
      if ( (pk instanceof PublicKeyEC) && (pkwithparams instanceof PublicKeyEC) ) {
        final PublicKeyEC pkec = (PublicKeyEC) pk;
        // The public key of IS and DV certificate do not have any parameters so we have to do some magic to get a complete EC public key
        final ECParameterSpec spec = pkec.getParams();
        if (spec == null) {
          final PublicKeyEC pkecp = (PublicKeyEC) pkwithparams;
          final ECParameterSpec pkspec = pkecp.getParams();
            if (pkspec != null) {
              final org.bouncycastle.jce.spec.ECParameterSpec bcspec = EC5Util.convertSpec(pkspec, false);
              final java.security.spec.ECPoint p = pkec.getW();
              final org.bouncycastle.math.ec.ECPoint ecp = EC5Util.convertPoint(pkspec, p, false);
              final ECPublicKeySpec pubKey = new ECPublicKeySpec(ecp, bcspec);
View Full Code Here

      log.debug("getKeyGenSpec: ECPublicKey");
      final ECPublicKey ecpub = (ECPublicKey) pk;
      final java.security.spec.ECParameterSpec sunsp = ecpub.getParams();
      final EllipticCurve ecurve = new EllipticCurve(sunsp.getCurve().getField(), sunsp.getCurve().getA(), sunsp.getCurve().getB());
      //ECParameterSpec par = new ECNamedCurveSpec(null, sunsp.getCurve(), sunsp.getGenerator(), sunsp.getOrder(), BigInteger.valueOf(sunsp.getCofactor()));
      final ECParameterSpec params = new ECParameterSpec(ecurve, sunsp.getGenerator(), sunsp.getOrder(), sunsp.getCofactor());
      if (log.isDebugEnabled()) {
        log.debug("Fieldsize: "+params.getCurve().getField().getFieldSize());
        final EllipticCurve curve = params.getCurve();
        log.debug("CurveA: "+curve.getA().toString(16));
        log.debug("CurveB: "+curve.getB().toString(16));
        log.debug("CurveSeed: "+curve.getSeed());
        final ECFieldFp field = (ECFieldFp)curve.getField();
        log.debug("CurveSfield: "+field.getP().toString(16));
        final ECPoint p = params.getGenerator();
        log.debug("Generator: "+p.getAffineX().toString(16)+", "+p.getAffineY().toString(16));
        log.debug("Order: "+params.getOrder().toString(16));
        log.debug("CoFactor: "+params.getCofactor());       
      }
      ret = params;
    } else if (pk instanceof JCEECPublicKey) {
      log.debug("getKeyGenSpec: JCEECPublicKey");
      final JCEECPublicKey ecpub = (JCEECPublicKey) pk;
      final org.bouncycastle.jce.spec.ECParameterSpec bcsp = ecpub.getParameters();
      final ECCurve curve = bcsp.getCurve();
      //TODO: this probably does not work for key generation with the Sun PKCS#11 provider. Maybe seed needs to be set to null as above? Or something else, the BC curve is it the same?
      final ECParameterSpec params = new ECNamedCurveSpec(null, curve, bcsp.getG(), bcsp.getN(), bcsp.getH());
      ret = params;
      //EllipticCurve ecc = new EllipticCurve(curve.)
      //ECParameterSpec sp = new ECParameterSpec(, bcsp.getG(), bcsp.getN(), bcsp.getH().intValue());
    }
    return ret;
View Full Code Here

        // We need special handling here of CVC certificate with EC keys, because they lack EC parameters in all certs except the Root certificate (CVCA)
      PublicKey pubk = incert.getPublicKey();
      if ((pubk instanceof PublicKeyEC)) {
        PublicKeyEC pkec = (PublicKeyEC) pubk;
        // The public key of IS and DV certificate (CVC) do not have any parameters so we have to do some magic to get a complete EC public key
        ECParameterSpec spec = pkec.getParams();
        if (spec == null) {
          // We need to enrich this public key with parameters
          try {
            if (cafp != null) {
              String cafingerp = cafp;
View Full Code Here

                spec.getN(),
                spec.getH());
        }
        else
        {
            return new ECParameterSpec(
                ellipticCurve,
                new ECPoint(
                    spec.getG().getX().toBigInteger(),
                    spec.getG().getY().toBigInteger()),
                spec.getN(),
View Full Code Here

        this.ecSpec = null;
    }

    private ECParameterSpec createSpec(EllipticCurve ellipticCurve, ECDomainParameters dp)
    {
        return new ECParameterSpec(
                ellipticCurve,
                new ECPoint(
                        dp.getG().getX().toBigInteger(),
                        dp.getG().getY().toBigInteger()),
                        dp.getN(),
View Full Code Here

                X9ECParameters          ecP = new X9ECParameters((ASN1Sequence)params.getParameters());

                curve = ecP.getCurve();
                ellipticCurve = EC5Util.convertCurve(curve, ecP.getSeed());

                this.ecSpec = new ECParameterSpec(
                        ellipticCurve,
                        new ECPoint(
                                ecP.getG().getX().toBigInteger(),
                                ecP.getG().getY().toBigInteger()),
                        ecP.getN(),
View Full Code Here

        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(),
View Full Code Here

TOP

Related Classes of java.security.spec.ECParameterSpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.