}
    public byte[] getEncoded()    {        ASN1Encodable           params = null;        if (algorithm.equals("ECGOST3410"))        {            params = new DERNull();  // TODO - parameters not yet correct        }        else        {            if (ecSpec instanceof ECNamedCurveSpec)            {                DERObjectIdentifier curveOid = ECUtil.getNamedCurveOid(((ECNamedCurveSpec)ecSpec).getName());                                params = new X962Parameters(curveOid);            }            else if (ecSpec == null)            {                params = new X962Parameters(DERNull.INSTANCE);            }            else            {                ECField field = ecSpec.getCurve().getField();                X9ECParameters ecP;                org.bouncycastle.math.ec.ECPoint ecPoint;                ECCurve curve;                if (field instanceof ECFieldFp)                 {                                        curve = new ECCurve.Fp(((ECFieldFp)field).getP(), ecSpec.getCurve().getA(), ecSpec.getCurve().getB());                    ecPoint = new org.bouncycastle.math.ec.ECPoint.Fp(curve, curve.fromBigInteger(ecSpec.getGenerator().getAffineX()), curve.fromBigInteger(ecSpec.getGenerator().getAffineY()), withCompression);                }                else                {                    ECFieldF2m fieldF2m = (ECFieldF2m)field;                    int ks[] = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());                    curve = new ECCurve.F2m(fieldF2m.getM(), ks[0], ks[1], ks[2], ecSpec.getCurve().getA(), ecSpec.getCurve().getB());                    ecPoint = new org.bouncycastle.math.ec.ECPoint.F2m(curve, curve.fromBigInteger(ecSpec.getGenerator().getAffineX()), curve.fromBigInteger(ecSpec.getGenerator().getAffineY()), withCompression);                }                ecP = new X9ECParameters(                        curve,                        ecPoint,                        ecSpec.getOrder(),                        BigInteger.valueOf(ecSpec.getCofactor()),                        ecSpec.getCurve().getSeed());                params = new X962Parameters(ecP);            }        }        SubjectPublicKeyInfo info;                if (algorithm.equals("ECGOST3410"))        {            BigInteger      bX = this.q.getX().toBigInteger();            BigInteger      bY = this.q.getY().toBigInteger();            byte[]          encKey = new byte[64];                        byte[] val = bX.toByteArray();                        for (int i = 0; i != 32; i++)            {                encKey[i] = val[val.length - 1 - i];            }                        val = bY.toByteArray();                        for (int i = 0; i != 32; i++)            {                encKey[32 + i] = val[val.length - 1 - i];            }                        info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, gostParams.getDERObject()), new DEROctetString(encKey));        }        else        {            ECCurve curve = this.engineGetQ().getCurve();            if (curve instanceof ECCurve.Fp)            {                ASN1OctetString    p = (ASN1OctetString)(new X9ECPoint(new org.bouncycastle.math.ec.ECPoint.Fp(curve, this.getQ().getX(), this.getQ().getY(), withCompression)).getDERObject());                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), p.getOctets());            }            else            {                ASN1OctetString    p = (ASN1OctetString)(new X9ECPoint(new org.bouncycastle.math.ec.ECPoint.F2m(curve, this.getQ().getX(), this.getQ().getY(), withCompression)).getDERObject());                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), p.getOctets());            }        }                return info.getDEREncoded();    }