Examples of ECPublicKey


Examples of java.security.interfaces.ECPublicKey

        // public key encoding test
        //
        byte[]              pubEnc = aKeyPair.getPublic().getEncoded();
        KeyFactory          keyFac = KeyFactory.getInstance("ECDH", "BC");
        X509EncodedKeySpec  pubX509 = new X509EncodedKeySpec(pubEnc);
        ECPublicKey         pubKey = (ECPublicKey)keyFac.generatePublic(pubX509);

        if (!pubKey.getW().equals(((ECPublicKey)aKeyPair.getPublic()).getW()))
        {
            fail("public key encoding (Q test) failed");
        }

        if (!(pubKey.getParams() instanceof ECNamedCurveSpec))
        {
            fail("public key encoding not named curve");
        }

        //
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

        // public key encoding test
        //
        byte[]              pubEnc = vKey.getEncoded();
        KeyFactory          keyFac = KeyFactory.getInstance("ECDH", "BC");
        X509EncodedKeySpec  pubX509 = new X509EncodedKeySpec(pubEnc);
        ECPublicKey         pubKey = (ECPublicKey)keyFac.generatePublic(pubX509);

        if (!pubKey.getW().equals(((ECPublicKey)vKey).getW()))
        {
            fail("public key encoding (Q test) failed");
        }

        if (!(pubKey.getParams() instanceof ECNamedCurveSpec))
        {
            fail("public key encoding not named curve");
        }

        //
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

        // public key encoding test
        //
        byte[]              pubEnc = vKey.getEncoded();
        KeyFactory          keyFac = KeyFactory.getInstance("ECGOST3410", "BC");
        X509EncodedKeySpec  pubX509 = new X509EncodedKeySpec(pubEnc);
        ECPublicKey         pubKey = (ECPublicKey)keyFac.generatePublic(pubX509);

        if (!pubKey.getW().equals(((ECPublicKey)vKey).getW()))
        {
            fail("public key encoding (Q test) failed");
        }

        if (!(pubKey.getParams() instanceof ECNamedCurveSpec))
        {
            fail("public key encoding not named curve");
        }

        //
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

            putMPInt(((DSAPublicKey) key).getParams().getP());
            putMPInt(((DSAPublicKey) key).getParams().getQ());
            putMPInt(((DSAPublicKey) key).getParams().getG());
            putMPInt(((DSAPublicKey) key).getY());
        } else if (key instanceof ECPublicKey) {
            ECPublicKey ecKey = (ECPublicKey) key;
            ECParameterSpec ecParams = ecKey.getParams();
            String curveName = ECCurves.getCurveName(ecParams);
            putString(ECCurves.ECDSA_SHA2_PREFIX + curveName);
            putString(curveName);
            putBytes(ECCurves.encodeECPoint(ecKey.getW(), ecParams.getCurve()));
        } else {
            throw new IllegalStateException("Unsupported algorithm: " + key.getAlgorithm());
        }
    }
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

            putMPInt(((DSAPublicKey) key.getPublic()).getParams().getQ());
            putMPInt(((DSAPublicKey) key.getPublic()).getParams().getG());
            putMPInt(((DSAPublicKey) key.getPublic()).getY());
            putMPInt(((DSAPrivateKey) key.getPrivate()).getX());
        } else if (key.getPublic() instanceof ECPublicKey) {
            ECPublicKey ecPub = (ECPublicKey) key.getPublic();
            ECPrivateKey ecPriv = (ECPrivateKey) key.getPrivate();
            ECParameterSpec ecParams = ecPub.getParams();
            String curveName = ECCurves.getCurveName(ecParams);

            putString(ECCurves.ECDSA_SHA2_PREFIX + curveName);
            putString(curveName);
            putString(ECCurves.encodeECPoint(ecPub.getW(), ecParams.getCurve()));
            putMPInt(ecPriv.getS());
        } else {
            throw new IllegalStateException("Unsupported algorithm: " + key.getPublic().getAlgorithm());
        }
    }
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

        try {
            Signature verif;
            if (kp.getFirst().getPublic() instanceof DSAPublicKey) {
                verif = new SignatureDSA();
            } else if (kp.getFirst().getPublic() instanceof ECPublicKey) {
                ECPublicKey pubKey = (ECPublicKey) kp.getFirst().getPublic();
                verif = SignatureECDSA.getByCurveSize(pubKey.getParams());
            } else if (kp.getFirst().getPublic() instanceof RSAPublicKey) {
                verif = new SignatureRSA();
            } else {
                throw new SshException("Unsupported key type");
            }
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

            return d1.getY().equals(d2.getY())
                        && p1.getG().equals(p2.getG())
                        && 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;
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

    assertEquals("SHA1WithRSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithRSA;SHA1WithECDSA", rsa));
    assertEquals("SHA1WithRSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA256WithECDSA;SHA1WithECDSA;SHA1WithRSA", rsa));
    assertEquals("SHA1WithRSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithRSA", rsa));
    assertEquals("SHA1WithRSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithECDSA;SHA1WithRSA", rsa));

    ECPublicKey ecdsa = new MockECDSAPublicKey();
    assertEquals("SHA1WithECDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithECDSA;SHA1WithDSA", ecdsa));
    assertEquals("SHA1WithECDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithDSA;SHA1WithRSA;SHA1WithECDSA", ecdsa));
    assertEquals("SHA1WithECDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithECDSA", ecdsa));
    assertEquals("SHA1WithECDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithDSA;SHA1WithECDSA", ecdsa));
   
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

      } catch (InvalidKeySpecException e) {
        log.error("Error creating RSAPublicKey from spec: ", e);
        publicKey = pubKey;
      }     
    } else if (pubKey instanceof ECPublicKey) {
      ECPublicKey ecpk = (ECPublicKey)pubKey;
      try {
        ECPublicKeySpec ecspec = new ECPublicKeySpec(ecpk.getW(), ecpk.getParams()); // will throw NPE if key is "implicitlyCA"
        publicKey = KeyFactory.getInstance("EC").generatePublic(ecspec);
      } catch (InvalidKeySpecException e) {
        log.error("Error creating ECPublicKey from spec: ", e);
        publicKey = pubKey;
      } catch (NullPointerException e) {
View Full Code Here

Examples of java.security.interfaces.ECPublicKey

      } 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
TOP
Copyright © 2018 www.massapi.com. 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.