Package org.bouncycastle.jce.provider

Examples of org.bouncycastle.jce.provider.JCEECPublicKey


                    params.getG(), params.getN(), params.getH(), params
                            .getSeed()));
            kp = kpg.generateKeyPair();
            // The very old Problem... we need a certificate chain to
            // save a private key...
            JCEECPublicKey pubKey = (JCEECPublicKey)kp.getPublic();
            if (!compress)
            {
                pubKey.setPointFormat("UNCOMPRESSED");
            }
            byte[] x = pubKey.getQ().getX().toBigInteger().toByteArray();
            byte[] y = pubKey.getQ().getY().toBigInteger().toByteArray();
            if (x.length == y.length)
            {
                success = true;
            }
        }

        // The very old Problem... we need a certificate chain to
        // save a private key...

        Certificate[] chain = new Certificate[] { generateSelfSignedSoftECCert(
                kp, compress) };

        KeyStore keyStore = KeyStore.getInstance("BKS");
        keyStore.load(null, keyStorePass.toCharArray());

        keyStore.setCertificateEntry("ECCert", chain[0]);

        JCEECPrivateKey privateECKey = (JCEECPrivateKey)kp.getPrivate();
        keyStore.setKeyEntry("ECPrivKey", privateECKey, keyStorePass
                .toCharArray(), chain);

        // Test ec sign / verify
        JCEECPublicKey pub = (JCEECPublicKey)kp.getPublic();
        String oldPrivateKey = new String(Hex.encode(privateECKey.getEncoded()));
        String oldPublicKey = new String(Hex.encode(pub.getEncoded()));
        JCEECPrivateKey newKey = (JCEECPrivateKey)keyStore.getKey("ECPrivKey",
                keyStorePass.toCharArray());
        JCEECPublicKey newPubKey = (JCEECPublicKey)keyStore.getCertificate(
                "ECCert").getPublicKey();
        if (!compress)
        {
            newKey.setPointFormat("UNCOMPRESSED");
            newPubKey.setPointFormat("UNCOMPRESSED");
        }

        String newPrivateKey = new String(Hex.encode(newKey.getEncoded()));
        String newPublicKey = new String(Hex.encode(newPubKey.getEncoded()));

        if (!oldPrivateKey.equals(newPrivateKey))
        {
            fail("failed private key comparison");
        }
View Full Code Here


    private X509Certificate generateSelfSignedSoftECCert(KeyPair kp,
            boolean compress) throws InvalidKeyException, SignatureException
    {
        X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
        JCEECPrivateKey privECKey = (JCEECPrivateKey)kp.getPrivate();
        JCEECPublicKey pubECKey = (JCEECPublicKey)kp.getPublic();
        if (!compress)
        {
            privECKey.setPointFormat("UNCOMPRESSED");
            pubECKey.setPointFormat("UNCOMPRESSED");
        }
        certGen.setSignatureAlgorithm("ECDSAwithSHA1");
        certGen.setSerialNumber(BigInteger.valueOf(1));
        certGen.setIssuerDN(new X509Principal("CN=Software emul (EC Cert)"));
        certGen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
View Full Code Here

    int len = -1;
    if (pk instanceof RSAPublicKey) {
      final RSAPublicKey rsapub = (RSAPublicKey) pk;
      len = rsapub.getModulus().bitLength();
    } else if (pk instanceof JCEECPublicKey) {
      final JCEECPublicKey ecpriv = (JCEECPublicKey) pk;
      final org.bouncycastle.jce.spec.ECParameterSpec spec = ecpriv.getParameters();
      if (spec != null) {
        len = spec.getN().bitLength();       
      } else {
        // We support the key, but we don't know the key length
        len = 0;
      }
    } else if (pk instanceof ECPublicKey) {
      final ECPublicKey ecpriv = (ECPublicKey) pk;
      final java.security.spec.ECParameterSpec spec = ecpriv.getParams();
      if (spec != null) {
        len = spec.getOrder().bitLength(); // does this really return something we expect?
      } else {
        // We support the key, but we don't know the key length
        len = 0;
View Full Code Here

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

            assertEquals(AlgorithmConstants.SIGALG_SHA256_WITH_ECDSA, sigAlg);
            assertTrue("Error in created ca certificate", cert.getSubjectDN().toString().equals("CN=TESTECDSA"));
            assertTrue("Creating CA failed", info.getSubjectDN().equals("CN=TESTECDSA"));
            PublicKey pk = cert.getPublicKey();
            if (pk instanceof JCEECPublicKey) {
                JCEECPublicKey ecpk = (JCEECPublicKey) pk;
                assertEquals(ecpk.getAlgorithm(), "EC");
                org.bouncycastle.jce.spec.ECParameterSpec spec = ecpk.getParameters();
                assertNotNull("ImplicitlyCA must have null spec", spec);
            } else {
                assertTrue("Public key is not EC", false);
            }
View Full Code Here

            X509Certificate cert = (X509Certificate) info.getCertificateChain().iterator().next();
            assertTrue("Error in created ca certificate", cert.getSubjectDN().toString().equals("CN=TESTECDSAImplicitlyCA"));
            assertTrue("Creating CA failed", info.getSubjectDN().equals("CN=TESTECDSAImplicitlyCA"));
            PublicKey pk = cert.getPublicKey();
            if (pk instanceof JCEECPublicKey) {
                JCEECPublicKey ecpk = (JCEECPublicKey) pk;
                assertEquals(ecpk.getAlgorithm(), "EC");
                org.bouncycastle.jce.spec.ECParameterSpec spec = ecpk.getParameters();
                assertNull("ImplicitlyCA must have null spec", spec);

            } else {
                assertTrue("Public key is not EC", false);
            }
View Full Code Here

        X509Certificate cert = (X509Certificate) signSession.createCertificate(admin, "foo", "foo123", selfcert);
        assertNotNull("Misslyckades skapa cert", cert);
        log.debug("Cert=" + cert.toString());
        PublicKey pk = cert.getPublicKey();
        if (pk instanceof JCEECPublicKey) {
            JCEECPublicKey ecpk = (JCEECPublicKey) pk;
            assertEquals(ecpk.getAlgorithm(), "EC");
            org.bouncycastle.jce.spec.ECParameterSpec spec = ecpk.getParameters();
            assertNotNull("ImplicitlyCA must have null spec", spec);
        } else {
            assertTrue("Public key is not EC", false);
        }
        try {
View Full Code Here

        Certificate cert = CertTools.getCertfromByteArray(resp.getResponseMessage());
        assertNotNull("Failed to create certificate", cert);
        log.debug("Cert=" + cert.toString());
        PublicKey pk = cert.getPublicKey();
        if (pk instanceof JCEECPublicKey) {
            JCEECPublicKey ecpk = (JCEECPublicKey) pk;
            assertEquals(ecpk.getAlgorithm(), "EC");
            org.bouncycastle.jce.spec.ECParameterSpec spec = ecpk.getParameters();
            assertNotNull("ImplicitlyCA must have null spec", spec);
        } else {
            assertTrue("Public key is not EC", false);
        }
        try {
View Full Code Here

        X509Certificate cert = (X509Certificate) signSession.createCertificate(admin, "fooecdsa", "foo123", selfcert);
        assertNotNull("Misslyckades skapa cert", cert);
        log.debug("Cert=" + cert.toString());
        PublicKey pk = cert.getPublicKey();
        if (pk instanceof JCEECPublicKey) {
            JCEECPublicKey ecpk = (JCEECPublicKey) pk;
            assertEquals(ecpk.getAlgorithm(), "EC");
            org.bouncycastle.jce.spec.ECParameterSpec spec = ecpk.getParameters();
            assertNotNull("ImplicitlyCA must have null spec", spec);
        } else {
            assertTrue("Public key is not EC", false);
        }
        try {
View Full Code Here

        Certificate cert = CertTools.getCertfromByteArray(resp.getResponseMessage());
        assertNotNull("Failed to create certificate", cert);
        log.debug("Cert=" + cert.toString());
        PublicKey pk = cert.getPublicKey();
        if (pk instanceof JCEECPublicKey) {
            JCEECPublicKey ecpk = (JCEECPublicKey) pk;
            assertEquals(ecpk.getAlgorithm(), "EC");
            org.bouncycastle.jce.spec.ECParameterSpec spec = ecpk.getParameters();
            assertNotNull("ImplicitlyCA must have null spec", spec);
        } else {
            assertTrue("Public key is not EC", false);
        }
        try {
View Full Code Here

TOP

Related Classes of org.bouncycastle.jce.provider.JCEECPublicKey

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.