Example usage for org.bouncycastle.math.ec ECCurve.Fp createPoint

List of usage examples for org.bouncycastle.math.ec ECCurve.Fp createPoint

Introduction

In this page you can find the example usage for org.bouncycastle.math.ec ECCurve.Fp createPoint.

Prototype

public ECPoint createPoint(BigInteger x, BigInteger y) 

Source Link

Usage

From source file:de.tsenger.animamea.tools.Converter.java

License:Open Source License

/**
 * Dekodiert aus dem bergebenen Byte-Array einen ECPoint. Das bentigte
 * prime field p wird aus der bergebenen Kurve bernommen Das erste Byte
 * muss den Wert 0x04 enthalten (uncompressed point).
 * /*ww w  .ja  v a 2s.c  om*/
 * @param value
 *            Byte Array der Form {0x04 || x-Bytes[] || y-Bytes[]}
 * @param curve
 *            Die Kurve auf der der Punkt liegen soll.
 * @return Point generiert aus den Input-Daten
 * @throws IllegalArgumentException
 *             Falls das erste Byte nicht den Wert 0x04 enthlt, enthlt das
 *             bergebene Byte-Array offensichtlich keinen unkomprimierten Punkt
 */
public static ECPoint byteArrayToECPoint(byte[] value, ECCurve.Fp curve) throws IllegalArgumentException {
    byte[] x = new byte[(value.length - 1) / 2];
    byte[] y = new byte[(value.length - 1) / 2];
    if (value[0] != (byte) 0x04)
        throw new IllegalArgumentException("No uncompressed Point found!");
    else {
        System.arraycopy(value, 1, x, 0, (value.length - 1) / 2);
        System.arraycopy(value, 1 + ((value.length - 1) / 2), y, 0, (value.length - 1) / 2);
        //         ECFieldElement.Fp xE = new ECFieldElement.Fp(curve.getQ(),
        //               new BigInteger(1, x));
        //         ECFieldElement.Fp yE = new ECFieldElement.Fp(curve.getQ(),
        //               new BigInteger(1, y));
        //         ECPoint point = new ECPoint.Fp(curve, xE, yE);
        ECPoint point = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));
        return point;
    }

}