Java Code Examples for sun.security.util.ECUtil#decodePoint()

The following examples show how to use sun.security.util.ECUtil#decodePoint() . 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: ECKeyPairGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private KeyPair generateKeyPairNative(SecureRandom random)
    throws Exception {

    ECParameterSpec ecParams = (ECParameterSpec) params;
    byte[] encodedParams = ECUtil.encodeECParameterSpec(null, ecParams);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    random.nextBytes(seed);
    Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

    // The 'params' object supplied above is equivalent to the native
    // one so there is no need to fetch it.
    // keyBytes[0] is the encoding of the native private key
    BigInteger s = new BigInteger(1, (byte[]) keyBytes[0]);

    PrivateKey privateKey = new ECPrivateKeyImpl(s, ecParams);

    // keyBytes[1] is the encoding of the native public key
    byte[] pubKey = (byte[]) keyBytes[1];
    ECPoint w = ECUtil.decodePoint(pubKey, ecParams.getCurve());
    PublicKey publicKey = new ECPublicKeyImpl(w, ecParams);

    return new KeyPair(publicKey, privateKey);
}
 
Example 2
Source File: ECKeyPairGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private KeyPair generateKeyPairNative(SecureRandom random)
    throws Exception {

    ECParameterSpec ecParams = (ECParameterSpec) params;
    byte[] encodedParams = ECUtil.encodeECParameterSpec(null, ecParams);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    random.nextBytes(seed);
    Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

    // The 'params' object supplied above is equivalent to the native
    // one so there is no need to fetch it.
    // keyBytes[0] is the encoding of the native private key
    BigInteger s = new BigInteger(1, (byte[]) keyBytes[0]);

    PrivateKey privateKey = new ECPrivateKeyImpl(s, ecParams);

    // keyBytes[1] is the encoding of the native public key
    byte[] pubKey = (byte[]) keyBytes[1];
    ECPoint w = ECUtil.decodePoint(pubKey, ecParams.getCurve());
    PublicKey publicKey = new ECPublicKeyImpl(w, ecParams);

    return new KeyPair(publicKey, privateKey);
}
 
Example 3
Source File: SM2PublicKeyImpl.java    From julongchain with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseKeyBits() throws InvalidKeyException {
    AlgorithmParameters algorithmParameters = this.algid.getParameters();
    if (algorithmParameters == null) {
        throw new InvalidKeyException("EC domain parameters must be encoded in the algorithm identifier");
    } else {
        try {
            this.params = algorithmParameters.getParameterSpec(ECParameterSpec.class);
            this.w = ECUtil.decodePoint(this.key, this.params.getCurve());
        } catch (IOException var3) {
            throw new InvalidKeyException("Invalid EC key", var3);
        } catch (InvalidParameterSpecException var4) {
            throw new InvalidKeyException("Invalid EC key", var4);
        }
    }
}
 
Example 4
Source File: ECKeyPairGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECUtil.encodeECParameterSpec(null, (ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.
        // keyBytes[0] is the encoding of the native private key
        BigInteger s = new BigInteger(1, (byte[])keyBytes[0]);

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // keyBytes[1] is the encoding of the native public key
        ECPoint w = ECUtil.decodePoint((byte[])keyBytes[1],
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
Example 5
Source File: ECDHKeyExchange.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
SecretKey getAgreedSecret(
        byte[] encodedPoint) throws SSLHandshakeException {
    try {
        ECParameterSpec params = publicKey.getParams();
        ECPoint point =
                ECUtil.decodePoint(encodedPoint, params.getCurve());
        KeyFactory kf = KeyFactory.getInstance("EC");
        ECPublicKeySpec spec = new ECPublicKeySpec(point, params);
        PublicKey peerPublicKey = kf.generatePublic(spec);
        return getAgreedSecret(peerPublicKey);
    } catch (GeneralSecurityException | java.io.IOException e) {
        throw (SSLHandshakeException) new SSLHandshakeException(
            "Could not generate secret").initCause(e);
    }
}
 
Example 6
Source File: ECKeyPairGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECUtil.encodeECParameterSpec(null, (ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.
        // keyBytes[0] is the encoding of the native private key
        BigInteger s = new BigInteger(1, (byte[])keyBytes[0]);

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // keyBytes[1] is the encoding of the native public key
        ECPoint w = ECUtil.decodePoint((byte[])keyBytes[1],
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
Example 7
Source File: ECKeyPairGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECUtil.encodeECParameterSpec(null, (ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.
        // keyBytes[0] is the encoding of the native private key
        BigInteger s = new BigInteger(1, (byte[])keyBytes[0]);

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // keyBytes[1] is the encoding of the native public key
        ECPoint w = ECUtil.decodePoint((byte[])keyBytes[1],
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
Example 8
Source File: ECKeyPairGenerator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECUtil.encodeECParameterSpec(null, (ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.
        // keyBytes[0] is the encoding of the native private key
        BigInteger s = new BigInteger(1, (byte[])keyBytes[0]);

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // keyBytes[1] is the encoding of the native public key
        ECPoint w = ECUtil.decodePoint((byte[])keyBytes[1],
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
Example 9
Source File: ECKeyPairGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECUtil.encodeECParameterSpec(null, (ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.
        // keyBytes[0] is the encoding of the native private key
        BigInteger s = new BigInteger(1, (byte[])keyBytes[0]);

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // keyBytes[1] is the encoding of the native public key
        ECPoint w = ECUtil.decodePoint((byte[])keyBytes[1],
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
Example 10
Source File: JsseJce.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve)
        throws java.io.IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 11
Source File: P11ECKeyFactory.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 12
Source File: JsseJce.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve)
        throws java.io.IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 13
Source File: JsseJce.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve)
        throws java.io.IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 14
Source File: P11ECKeyFactory.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 15
Source File: P11ECKeyFactory.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 16
Source File: P11ECKeyFactory.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 17
Source File: P11ECKeyFactory.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 18
Source File: P11ECKeyFactory.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 19
Source File: P11ECKeyFactory.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECUtil.decodePoint(encoded, curve);
}
 
Example 20
Source File: P11ECKeyFactory.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECUtil.decodePoint(encoded, curve);
}