public byte[] getEncoded()
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
X962Parameters params = null;
if (ecSpec instanceof ECNamedCurveParameterSpec)
{
params = new X962Parameters(X962NamedCurves.getOID(((ECNamedCurveParameterSpec)ecSpec).getName()));
}
else
{
ECParameterSpec p = (ECParameterSpec)ecSpec;
X9ECParameters ecP = new X9ECParameters(
p.getCurve(),
new org.bouncycastle.math.ec.ECPoint.Fp(p.getG().getCurve(), p.getG().getX(), p.getG().getY(), withCompression),
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
{
ASN1OctetString p = (ASN1OctetString)(new X9ECPoint(new org.bouncycastle.math.ec.ECPoint.Fp(this.getQ().getCurve(), this.getQ().getX(), this.getQ().getY(), withCompression)).getDERObject());
info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), p.getOctets());
}
try
{
dOut.writeObject(info);