public byte[] toASN1(){
  try {
    byte[] privKeyBytes=getPrivKeyBytes();
    ByteArrayOutputStream baos=new ByteArrayOutputStream(400);
    DERSequenceGenerator seq=new DERSequenceGenerator(baos);
    seq.addObject(new ASN1Integer(1));
    seq.addObject(new DEROctetString(privKeyBytes));
    seq.addObject(new DERTaggedObject(0,CURVE_PARAMS.toASN1Primitive()));
    seq.addObject(new DERTaggedObject(1,new DERBitString(getPubKey())));
    seq.close();
    return baos.toByteArray();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}

public byte [ ] toASN1 ( ) { try { byte [ ] privKeyBytes = getPrivKeyBytes ( ) ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( 400 ) ; DERSequenceGenerator seq = new DERSequenceGenerator ( baos ) ; seq . addObject ( new ASN1Integer ( 1 ) ) ; seq . addObject ( new DEROctetString ( privKeyBytes ) ) ; seq . addObject ( new DERTaggedObject ( 0 , CURVE_PARAMS . toASN1Primitive ( ) ) ) ; seq . addObject ( new DERTaggedObject ( 1 , new DERBitString ( getPubKey ( ) ) ) ) ; seq . close ( ) ; return baos . toByteArray ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } }
output this eckey as an asn . 1 encoded private key , as understood by openssl or used by bitcoin core in its wallet storage format .
