@Override
public byte[] getEncoded() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SEQUENCE privateKeyInfo = new SEQUENCE();
privateKeyInfo.addElement(new INTEGER(0));
SEQUENCE algid = new SEQUENCE();
algid.addElement(new OBJECT_IDENTIFIER("1.2.840.10045.2.1"));
algid.addElement(new OBJECT_IDENTIFIER(EcCore.getOID(params)));
privateKeyInfo.addElement(algid);
SEQUENCE ecPrivateKey = new SEQUENCE();
ecPrivateKey.addElement(new INTEGER(1));
ecPrivateKey
.addElement(new OCTET_STRING(EcCore.fieldElemToBytes(S, params)));
try {
ecPrivateKey.encode(baos);
} catch (IOException ioe) {
throw new RuntimeException("Internal ASN.1 encoding error", ioe);
}
privateKeyInfo.addElement(new OCTET_STRING(baos.toByteArray()));