Example usage for org.bouncycastle.asn1.x9 X9ECPoint getPoint

List of usage examples for org.bouncycastle.asn1.x9 X9ECPoint getPoint

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x9 X9ECPoint getPoint.

Prototype

public synchronized ECPoint getPoint() 

Source Link

Usage

From source file:eu.betaas.taas.securitymanager.common.ec.ECKeyPairGen.java

License:Apache License

/**
 * A method to reconstruct an ECPublicKey from a SubjectPublicKeyInfo of a 
 * certificate // w  w  w .jav a 2s  .co m
 * @param info: SubjectPublicKeyInfo in a X509Certificate
 * @return: ECPublicKeyParameters
 */
public static ECPublicKeyParameters generateECPublicKey(SubjectPublicKeyInfo info) {
    X962Parameters as = (X962Parameters) info.getAlgorithm().getParameters();
    DERSequence aa = (DERSequence) as.getParameters();
    Enumeration en = aa.getObjects();
    ECCurve curve = null;
    org.bouncycastle.math.ec.ECPoint g = null;
    byte[] seed = null;
    BigInteger h = null;
    BigInteger n = null;
    while (en.hasMoreElements()) {
        Object oen = en.nextElement();
        if (oen instanceof X9Curve) {
            curve = ((X9Curve) oen).getCurve();
            seed = ((X9Curve) oen).getSeed();
        } else if (oen instanceof X9ECPoint) {
            g = ((X9ECPoint) oen).getPoint();
        } else if (oen instanceof ASN1Integer) {
            BigInteger xoen = ((ASN1Integer) oen).getValue();
            if (xoen.equals(BigInteger.ONE))
                h = xoen;
            else
                n = xoen;
        }
    }

    ASN1OctetString key = new DEROctetString(info.getPublicKeyData().getBytes());
    X9ECPoint derQ = new X9ECPoint(curve, key);

    ECDomainParameters dParams = new ECDomainParameters(curve, g, n, h, seed);

    return new ECPublicKeyParameters(derQ.getPoint(), dParams);
}