Example usage for org.bouncycastle.jce.spec ECParameterSpec ECParameterSpec

List of usage examples for org.bouncycastle.jce.spec ECParameterSpec ECParameterSpec

Introduction

In this page you can find the example usage for org.bouncycastle.jce.spec ECParameterSpec ECParameterSpec.

Prototype

public ECParameterSpec(ECCurve curve, ECPoint G, BigInteger n, BigInteger h) 

Source Link

Usage

From source file:com.google.u2f.server.impl.BouncyCastleCrypto.java

License:Open Source License

@Override
public PublicKey decodePublicKey(byte[] encodedPublicKey) throws U2FException {
    try {//from  ww w  .j  a v a  2  s. c o  m
        X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
        ECPoint point;
        try {
            point = curve.getCurve().decodePoint(encodedPublicKey);
        } catch (RuntimeException e) {
            throw new U2FException("Couldn't parse user public key", e);
        }

        return KeyFactory.getInstance("ECDSA").generatePublic(new ECPublicKeySpec(point,
                new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));
    } catch (InvalidKeySpecException e) {
        throw new U2FException("Error when decoding public key", e);
    } catch (NoSuchAlgorithmException e) {
        throw new U2FException("Error when decoding public key", e);
    }
}

From source file:com.google.u2f.TestUtils.java

License:Open Source License

public static PrivateKey parsePrivateKey(String keyBytesHex) {
    try {//from   w ww . jav  a  2s  .  c  om
        KeyFactory fac = KeyFactory.getInstance("ECDSA");
        X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
        ECParameterSpec curveSpec = new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(),
                curve.getH());
        ECPrivateKeySpec keySpec = new ECPrivateKeySpec(new BigInteger(keyBytesHex, 16), curveSpec);
        return fac.generatePrivate(keySpec);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (InvalidKeySpecException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.google.u2f.TestUtils.java

License:Open Source License

public static PublicKey parsePublicKey(byte[] keyBytes) {
    try {/*w  w w  .  j  av a2  s. com*/
        X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
        ECParameterSpec curveSpec = new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(),
                curve.getH());
        ECPoint point = curve.getCurve().decodePoint(keyBytes);
        return KeyFactory.getInstance("ECDSA").generatePublic(new ECPublicKeySpec(point, curveSpec));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (InvalidKeySpecException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.jin.u2f.crypto.BouncyCastleCrypto.java

License:Open Source License

public PublicKey decodePublicKey(byte[] encodedPublicKey) throws U2fBadInputException {
    try {/*from  www.  java2 s.c  o  m*/
        X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
        ECPoint point;
        try {
            point = curve.getCurve().decodePoint(encodedPublicKey);
        } catch (RuntimeException e) {
            throw new U2fBadInputException("Could not parse user public key", e);
        }

        return KeyFactory.getInstance("ECDSA").generatePublic(new ECPublicKeySpec(point,
                new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));
    } catch (GeneralSecurityException e) { // This should not happen
        throw new RuntimeException(e);
    }
}

From source file:com.yubico.u2f.crypto.BouncyCastleCrypto.java

License:Open Source License

@Override
public PublicKey decodePublicKey(byte[] encodedPublicKey) throws U2fBadInputException {
    try {/*from  w w w . j a v  a2  s .  co  m*/
        X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
        ECPoint point;
        try {
            point = curve.getCurve().decodePoint(encodedPublicKey);
        } catch (RuntimeException e) {
            throw new U2fBadInputException("Could not parse user public key", e);
        }

        return KeyFactory.getInstance("ECDSA").generatePublic(new ECPublicKeySpec(point,
                new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));
    } catch (GeneralSecurityException e) { //This should not happen
        throw new RuntimeException(e);
    }
}

From source file:de.tsenger.animamea.asn1.AmECPublicKey.java

License:Open Source License

@Override
public ECParameterSpec getParameters() {
    ECCurve.Fp curve = new ECCurve.Fp(getP(), getA(), getB());
    ECPoint pointG = byteArrayToECPoint(getG(), curve);
    ECParameterSpec ecParameterSpec = new ECParameterSpec(curve, pointG, getR(), getF());
    return ecParameterSpec;
}

From source file:nl.arietimmerman.u2f.server.CryptoHelper.java

License:Open Source License

/**
 * //from  ww  w  .j  a  v a 2 s  .  co  m
 * @param encodedPublicKey This is the (uncompressed) x,y-representation of a curve point on the P-256 NIST elliptic curve.
 * @return
 */
public static PublicKey decodePublicKey(byte[] encodedPublicKey) {
    PublicKey result = null;

    try {

        X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
        ECPoint point = curve.getCurve().decodePoint(encodedPublicKey);

        result = KeyFactory.getInstance("ECDSA", new BouncyCastleProvider()).generatePublic(new ECPublicKeySpec(
                point, new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));

    } catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    return result;
}

From source file:org.wso2.carbon.identity.application.authenticator.fido.u2f.crypto.BouncyCastleCrypto.java

License:Open Source License

@Override
public PublicKey decodePublicKey(byte[] encodedPublicKey) throws U2fException {
    try {/*from  w w w. j  a va  2s. c om*/
        X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
        ECPoint point;
        try {
            point = curve.getCurve().decodePoint(encodedPublicKey);
        } catch (RuntimeException e) {
            throw new U2fException("Could not parse user public key", e);
        }

        return KeyFactory.getInstance("ECDSA").generatePublic(new ECPublicKeySpec(point,
                new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));
    } catch (InvalidKeySpecException e) {
        throw new U2fException(ERROR_DECODING_PUBLIC_KEY, e);
    } catch (NoSuchAlgorithmException e) {
        throw new U2fException(ERROR_DECODING_PUBLIC_KEY, e);
    }
}

From source file:org.xdi.oxauth.crypto.signature.BouncyCastleSignatureVerification.java

License:MIT License

@Override
public PublicKey decodePublicKey(byte[] encodedPublicKey) throws SignatureException {
    X9ECParameters curve = SECNamedCurves.getByName("SECP256R1");
    ECPoint point = curve.getCurve().decodePoint(encodedPublicKey);

    try {/*from   ww w .j a v a  2  s. com*/
        return KeyFactory.getInstance("ECDSA").generatePublic(new ECPublicKeySpec(point,
                new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));
    } catch (GeneralSecurityException ex) {
        throw new SignatureException(ex);
    }
}

From source file:org.xdi.oxauth.crypto.signature.SHA256withECDSASignatureVerification.java

License:MIT License

@Override
public PublicKey decodePublicKey(byte[] encodedPublicKey) throws SignatureException {
    X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
    ECPoint point = curve.getCurve().decodePoint(encodedPublicKey);

    try {/*ww w . jav a2  s.c  o  m*/
        return KeyFactory.getInstance("ECDSA").generatePublic(new ECPublicKeySpec(point,
                new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));
    } catch (GeneralSecurityException ex) {
        throw new SignatureException(ex);
    }
}