Java Code Examples for java.security.interfaces.ECPublicKey#getParams()

The following examples show how to use java.security.interfaces.ECPublicKey#getParams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientHandshaker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void serverKeyExchange(ECDH_ServerKeyExchange mesg)
        throws IOException {
    if (debug != null && Debug.isOn("handshake")) {
        mesg.print(System.out);
    }
    ECPublicKey key = mesg.getPublicKey();
    ecdh = new ECDHCrypt(key.getParams(), sslContext.getSecureRandom());
    ephemeralServerKey = key;

    // check constraints of EC PublicKey
    if (!algorithmConstraints.permits(
        EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), ephemeralServerKey)) {

        throw new SSLHandshakeException("ECDH ServerKeyExchange " +
                "does not comply to algorithm constraints");
    }
}
 
Example 2
Source File: ClientHandshaker.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void serverKeyExchange(ECDH_ServerKeyExchange mesg)
        throws IOException {
    if (debug != null && Debug.isOn("handshake")) {
        mesg.print(System.out);
    }
    ECPublicKey key = mesg.getPublicKey();
    ecdh = new ECDHCrypt(key.getParams(), sslContext.getSecureRandom());
    ephemeralServerKey = key;

    // check constraints of EC PublicKey
    if (!algorithmConstraints.permits(
        EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), ephemeralServerKey)) {

        throw new SSLHandshakeException("ECDH ServerKeyExchange " +
                "does not comply to algorithm constraints");
    }
}
 
Example 3
Source File: ClientHandshaker.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void serverKeyExchange(ECDH_ServerKeyExchange mesg)
        throws IOException {
    if (debug != null && Debug.isOn("handshake")) {
        mesg.print(System.out);
    }
    ECPublicKey key = mesg.getPublicKey();
    ecdh = new ECDHCrypt(key.getParams(), sslContext.getSecureRandom());
    ephemeralServerKey = key;

    // check constraints of EC PublicKey
    if (!algorithmConstraints.permits(
        EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), ephemeralServerKey)) {

        throw new SSLHandshakeException("ECDH ServerKeyExchange " +
                "does not comply to algorithm constraints");
    }
}
 
Example 4
Source File: DOMKeyValue.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
EC(PublicKey key) throws KeyException {
    super(key);
    ECPublicKey ecKey = (ECPublicKey)key;
    ECPoint ecPoint = ecKey.getW();
    ecParams = ecKey.getParams();
    ecPublicKey = encodePoint(ecPoint, ecParams.getCurve());
}
 
Example 5
Source File: JCEECPublicKey.java    From ripple-lib-java with ISC License 5 votes vote down vote up
public JCEECPublicKey(
    ECPublicKey     key)
{
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
    this.q = EC5Util.convertPoint(this.ecSpec, key.getW(), false);
}
 
Example 6
Source File: DOMKeyValue.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
EC(PublicKey key) throws KeyException {
    super(key);
    ECPublicKey ecKey = (ECPublicKey)key;
    ECPoint ecPoint = ecKey.getW();
    ecParams = ecKey.getParams();
    try {
        AccessController.doPrivileged(
            new PrivilegedExceptionAction<Void>() {
                public Void run() throws
                    ClassNotFoundException, NoSuchMethodException
                {
                    getMethods();
                    return null;
                }
            }
        );
    } catch (PrivilegedActionException pae) {
        throw new KeyException("ECKeyValue not supported",
                                pae.getException());
    }
    Object[] args = new Object[] { ecPoint, ecParams.getCurve() };
    try {
        ecPublicKey = (byte[])encodePoint.invoke(null, args);
    } catch (IllegalAccessException iae) {
        throw new KeyException(iae);
    } catch (InvocationTargetException ite) {
        throw new KeyException(ite);
    }
}
 
Example 7
Source File: BCECGOST3410PublicKey.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public BCECGOST3410PublicKey(
    ECPublicKey key)
{
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
    this.q = EC5Util.convertPoint(this.ecSpec, key.getW(), false);
}
 
Example 8
Source File: DOMKeyValue.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
EC(PublicKey key) throws KeyException {
    super(key);
    ECPublicKey ecKey = (ECPublicKey)key;
    ECPoint ecPoint = ecKey.getW();
    ecParams = ecKey.getParams();
    ecPublicKey = encodePoint(ecPoint, ecParams.getCurve());
}
 
Example 9
Source File: EcKey.java    From azure-keyvault-java with MIT License 5 votes vote down vote up
private JsonWebKeyCurveName getCurveFromKeyPair(KeyPair keyPair) {
	try {
		ECPublicKey key = (ECPublicKey) keyPair.getPublic();
		ECParameterSpec spec = key.getParams();
		EllipticCurve crv = spec.getCurve();
		
		List<JsonWebKeyCurveName> curveList = Arrays.asList(JsonWebKeyCurveName.P_256, JsonWebKeyCurveName.P_384, JsonWebKeyCurveName.P_521, JsonWebKeyCurveName.P_256K);
		
		for (JsonWebKeyCurveName curve : curveList) {
			ECGenParameterSpec gps = new ECGenParameterSpec(CURVE_TO_SPEC_NAME.get(curve));
			KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", _provider);
			kpg.initialize(gps);
			
			// Generate dummy keypair to get parameter spec.
			KeyPair apair = kpg.generateKeyPair();
			ECPublicKey apub = (ECPublicKey) apair.getPublic();
			ECParameterSpec aspec = apub.getParams();
			EllipticCurve acurve = aspec.getCurve();
			
			//Matches the parameter spec
			if (acurve.equals(crv)) {
				return curve;
			}
		}
		
		//Did not find a supported curve.
		throw new IllegalArgumentException ("Curve not supported.");
	} catch (GeneralSecurityException e) {
		throw new IllegalStateException(e);
	}
}
 
Example 10
Source File: BCDSTU4145PublicKey.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public BCDSTU4145PublicKey(
    ECPublicKey key)
{
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
    this.q = EC5Util.convertPoint(this.ecSpec, key.getW(), false);
}
 
Example 11
Source File: ClientHandshaker.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void serverKeyExchange(ECDH_ServerKeyExchange mesg)
        throws IOException {
    if (debug != null && Debug.isOn("handshake")) {
        mesg.print(System.out);
    }
    ECPublicKey key = mesg.getPublicKey();
    ecdh = new ECDHCrypt(key.getParams(), sslContext.getSecureRandom());
    ephemeralServerKey = key;
}
 
Example 12
Source File: ClientHandshaker.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void serverKeyExchange(ECDH_ServerKeyExchange mesg)
        throws IOException {
    if (debug != null && Debug.isOn("handshake")) {
        mesg.print(System.out);
    }
    ECPublicKey key = mesg.getPublicKey();
    ecdh = new ECDHCrypt(key.getParams(), sslContext.getSecureRandom());
    ephemeralServerKey = key;
}
 
Example 13
Source File: DOMKeyValue.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
EC(PublicKey key) throws KeyException {
    super(key);
    ECPublicKey ecKey = (ECPublicKey)key;
    ECPoint ecPoint = ecKey.getW();
    ecParams = ecKey.getParams();
    try {
        AccessController.doPrivileged(
            new PrivilegedExceptionAction<Void>() {
                public Void run() throws
                    ClassNotFoundException, NoSuchMethodException
                {
                    getMethods();
                    return null;
                }
            }
        );
    } catch (PrivilegedActionException pae) {
        throw new KeyException("ECKeyValue not supported",
                                pae.getException());
    }
    Object[] args = new Object[] { ecPoint, ecParams.getCurve() };
    try {
        ecPublicKey = (byte[])encodePoint.invoke(null, args);
    } catch (IllegalAccessException iae) {
        throw new KeyException(iae);
    } catch (InvocationTargetException ite) {
        throw new KeyException(ite);
    }
}
 
Example 14
Source File: BCECPublicKey.java    From ripple-lib-java with ISC License 5 votes vote down vote up
public BCECPublicKey(
    ECPublicKey key,
    ProviderConfiguration configuration)
{
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
    this.q = EC5Util.convertPoint(this.ecSpec, key.getW(), false);
}
 
Example 15
Source File: BCDSTU4145PublicKey.java    From ripple-lib-java with ISC License 5 votes vote down vote up
public BCDSTU4145PublicKey(
    ECPublicKey key)
{
    this.algorithm = key.getAlgorithm();
    this.ecSpec = key.getParams();
    this.q = EC5Util.convertPoint(this.ecSpec, key.getW(), false);
}
 
Example 16
Source File: DOMKeyValue.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
EC(PublicKey key) throws KeyException {
    super(key);
    ECPublicKey ecKey = (ECPublicKey)key;
    ECPoint ecPoint = ecKey.getW();
    ecParams = ecKey.getParams();
    try {
        AccessController.doPrivileged(
            new PrivilegedExceptionAction<Void>() {
                public Void run() throws
                    ClassNotFoundException, NoSuchMethodException
                {
                    getMethods();
                    return null;
                }
            }
        );
    } catch (PrivilegedActionException pae) {
        throw new KeyException("ECKeyValue not supported",
                                pae.getException());
    }
    Object[] args = new Object[] { ecPoint, ecParams.getCurve() };
    try {
        ecPublicKey = (byte[])encodePoint.invoke(null, args);
    } catch (IllegalAccessException iae) {
        throw new KeyException(iae);
    } catch (InvocationTargetException ite) {
        throw new KeyException(ite);
    }
}
 
Example 17
Source File: ECDHClientKeyExchange.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
ECDHClientKeyExchange(PublicKey publicKey) {
    ECPublicKey ecKey = (ECPublicKey)publicKey;
    ECPoint point = ecKey.getW();
    ECParameterSpec params = ecKey.getParams();
    encodedPoint = JsseJce.encodePoint(point, params.getCurve());
}
 
Example 18
Source File: ECDHClientKeyExchange.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
ECDHClientKeyExchange(PublicKey publicKey) {
    ECPublicKey ecKey = (ECPublicKey)publicKey;
    ECPoint point = ecKey.getW();
    ECParameterSpec params = ecKey.getParams();
    encodedPoint = JsseJce.encodePoint(point, params.getCurve());
}
 
Example 19
Source File: ECDHClientKeyExchange.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
ECDHClientKeyExchange(PublicKey publicKey) {
    ECPublicKey ecKey = (ECPublicKey)publicKey;
    ECPoint point = ecKey.getW();
    ECParameterSpec params = ecKey.getParams();
    encodedPoint = JsseJce.encodePoint(point, params.getCurve());
}
 
Example 20
Source File: ECDHClientKeyExchange.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
ECDHClientKeyExchange(PublicKey publicKey) {
    ECPublicKey ecKey = (ECPublicKey)publicKey;
    ECPoint point = ecKey.getW();
    ECParameterSpec params = ecKey.getParams();
    encodedPoint = JsseJce.encodePoint(point, params.getCurve());
}