* @return a PKCS8 representation of the key.
*/
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
{
X9ECParameters ecP = new X9ECParameters(
ecSpec.getCurve(),
ecSpec.getG(),
ecSpec.getN(),
ecSpec.getH(),
ecSpec.getSeed());
params = new X962Parameters(ecP);
}
PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), new ECPrivateKeyStructure(this.getD()).getDERObject());
try
{
dOut.writeObject(info);
dOut.close();
}
catch (IOException e)
{
throw new RuntimeException("Error encoding EC private key");
}