try { dOut.writeObject(info); dOut.close(); } catch (IOException e) { throw new RuntimeException("Error encoding EC public key"); }  return bOut.toByteArray();
return info.getDEREncoded();
    public byte[] getEncoded()    {        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();        DEROutputStream         dOut = new DEROutputStream(bOut);        X962Parameters          params = null;        if (ecSpec instanceof ECNamedCurveParameterSpec)        {            DERObjectIdentifier curveOid = ECUtil.getNamedCurveOid(((ECNamedCurveParameterSpec)ecSpec).getName());                        params = new X962Parameters(curveOid);        }        else if (ecSpec == null)        {            params = new X962Parameters(DERNull.INSTANCE);        }        else        {            ECParameterSpec         p = (ECParameterSpec)ecSpec;            ECCurve curve = p.getG().getCurve();            ECPoint generator;            if (curve instanceof ECCurve.Fp)             {                generator = new ECPoint.Fp(p.getG().getCurve(), p.getG().getX(), p.getG().getY(), withCompression);            }             else if (curve instanceof ECCurve.F2m)            {                generator = new ECPoint.F2m(p.getG().getCurve(), p.getG().getX(), p.getG().getY(), withCompression);            }             else             {                throw new UnsupportedOperationException("Subclass of ECPoint " + curve.getClass().toString() + "not supported");            }            X9ECParameters ecP = new X9ECParameters(                p.getCurve(), generator, p.getN(), p.getH(), p.getSeed());            params = new X962Parameters(ecP);        }        SubjectPublicKeyInfo info;                if (algorithm.equals("ECGOST3410"))        {            ASN1OctetString    p = (ASN1OctetString)(new X9ECPoint(new org.bouncycastle.math.ec.ECPoint.Fp(this.getQ().getCurve(), this.getQ().getX(), this.getQ().getY(), false)).getDERObject());                        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();            ASN1OctetString p;            if (curve instanceof ECCurve.Fp)             {                p = (ASN1OctetString)(new X9ECPoint(new ECPoint.Fp(curve, this.getQ().getX(), this.getQ().getY(), withCompression)).getDERObject());            }             else if (curve instanceof ECCurve.F2m)            {                p = (ASN1OctetString)(new X9ECPoint(new ECPoint.F2m(curve, this.getQ().getX(), this.getQ().getY(), withCompression)).getDERObject());            }             else             {                throw new UnsupportedOperationException("Subclass of ECPoint " + curve.getClass().toString() + "not supported");            }                        info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), p.getOctets());        }                try        {            dOut.writeObject(info);            dOut.close();        }        catch (IOException e)        {            throw new RuntimeException("Error encoding EC public key");        }        return bOut.toByteArray();    }