Package java.security.spec

Examples of java.security.spec.ECPrivateKeySpec


        ECPoint g = new ECPoint(BigInteger.ZERO, BigInteger.valueOf(2L));
        ECParameterSpec params =
            new ECParameterSpec(c, g, BigInteger.valueOf(5L), 10);
        BigInteger s = BigInteger.valueOf(5L);

        ECPrivateKeySpec ks = new ECPrivateKeySpec(s, params);
        BigInteger sRet = ks.getS();

        assertEquals(s, sRet);
        assertSame(s, sRet);
    }
View Full Code Here


            ECPointUtil.decodePoint(curve, Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
            new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n
            1); // h
       

        ECPrivateKeySpec priKey = new ECPrivateKeySpec(
            new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d
            spec);

        ECPublicKeySpec pubKey = new ECPublicKeySpec(
            ECPointUtil.decodePoint(curve, Hex.decode("025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70")), // Q
View Full Code Here

            curve,
            ECPointUtil.decodePoint(curve, Hex.decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G
            new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n
            4); // h
   
        ECPrivateKeySpec priKeySpec = new ECPrivateKeySpec(
            new BigInteger("145642755521911534651321230007534120304391871461646461466464667494947990"), // d
            params);
       
        ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(
            ECPointUtil.decodePoint(curve, Hex.decode("045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5")), // Q
View Full Code Here

    }
    public static ECPrivateKey getECPrivateKey(byte[] privateKey) {
        try {
            ECParameterSpec params = getECParameterSpec();

            ECPrivateKeySpec keySpec = new ECPrivateKeySpec(
                                           new BigInteger(1, privateKey), params);
            KeyFactory kf = KeyFactory.getInstance("EC");
            return (ECPrivateKey) kf.generatePrivate(keySpec);

        } catch (Exception ex) {
View Full Code Here

        EllipticCurve c =
            new EllipticCurve(new ECFieldFp(BigInteger.valueOf(5L)),
                              BigInteger.ZERO,
                              BigInteger.valueOf(4L));
        ECPoint g = new ECPoint(BigInteger.ZERO, BigInteger.valueOf(2L));
        new ECPrivateKeySpec(BigInteger.ZERO,
                new ECParameterSpec(c, g, BigInteger.valueOf(5L), 10));
       
    }
View Full Code Here

                              BigInteger.valueOf(4L));
        ECPoint g = new ECPoint(BigInteger.ZERO, BigInteger.valueOf(2L));

        // Test case 1: s is null
        try {
            new ECPrivateKeySpec(null,
                new ECParameterSpec(c, g, BigInteger.valueOf(5L), 10));
            fail("#1: Expected NPE not thrown");
        } catch (NullPointerException ok) {
        }


        // Test case 2: params is null
        try {
            new ECPrivateKeySpec(BigInteger.valueOf(0L), null);
            fail("#2: Expected NPE not thrown");
        } catch (NullPointerException ok) {
        }


        // Test case 3: both s and params are null
        try {
            new ECPrivateKeySpec(null, null);
            fail("#3: Expected NPE not thrown");
        } catch (NullPointerException ok) {
        }
    }
View Full Code Here

                              BigInteger.valueOf(4L));
        ECPoint g = new ECPoint(BigInteger.ZERO, BigInteger.valueOf(2L));
        ECParameterSpec params =
            new ECParameterSpec(c, g, BigInteger.valueOf(5L), 10);

        ECPrivateKeySpec ks = new ECPrivateKeySpec(BigInteger.ZERO, params);
        ECParameterSpec paramsRet = ks.getParams();
       
        assertEquals(params, paramsRet);
        assertSame(params, paramsRet);
    }
View Full Code Here

        ECPoint g = new ECPoint(BigInteger.ZERO, BigInteger.valueOf(2L));
        ECParameterSpec params =
            new ECParameterSpec(c, g, BigInteger.valueOf(5L), 10);
        BigInteger s = BigInteger.valueOf(5L);

        ECPrivateKeySpec ks = new ECPrivateKeySpec(s, params);
        BigInteger sRet = ks.getS();

        assertEquals(s, sRet);
        assertSame(s, sRet);
    }
View Full Code Here

          ECPrivateKey ecPrivKey = (ECPrivateKey) ecKeyPair.getPrivate();
          byte[] tmp = ecPrivKey.getEncoded();
          KeyFactory keyFab = KeyFactory.getInstance("EC", gooProv);
          keyFab.generatePrivate(new PKCS8EncodedKeySpec(tmp));
          ECPrivateKeySpec ecPrivSpec = new ECPrivateKeySpec(ecPrivKey.getS(),
              ecPrivKey.getParams());
          keyFab.generatePrivate(ecPrivSpec);

          ECPublicKey ecPubKey = (ECPublicKey) ecKeyPair.getPublic();
          tmp = ecPubKey.getEncoded(); // dont modify tmp now - is used below
View Full Code Here

      } catch (Exception e) {
        throw new InvalidKeySpecException("Invalid key encoding", e);
      }
    }
    if (keySpec instanceof ECPrivateKeySpec) {
      ECPrivateKeySpec spec = (ECPrivateKeySpec) keySpec;
      return new EcPrivateKeyImpl(spec.getS(), spec.getParams());
    }
    throw new IllegalArgumentException("Type of KeySpec is not supported");
  }
View Full Code Here

TOP

Related Classes of java.security.spec.ECPrivateKeySpec

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.