code: public byte[] toASN1() {
          try {
              byte[] privKeyBytes = getPrivKeyBytes();
              ByteArrayOutputStream baos = new ByteArrayOutputStream(400);
  
              // ASN1_SEQUENCE(EC_PRIVATEKEY) = {
              //   ASN1_SIMPLE(EC_PRIVATEKEY, version, LONG),
              //   ASN1_SIMPLE(EC_PRIVATEKEY, privateKey, ASN1_OCTET_STRING),
              //   ASN1_EXP_OPT(EC_PRIVATEKEY, parameters, ECPKPARAMETERS, 0),
              //   ASN1_EXP_OPT(EC_PRIVATEKEY, publicKey, ASN1_BIT_STRING, 1)
              // } ASN1_SEQUENCE_END(EC_PRIVATEKEY)
              DERSequenceGenerator seq = new DERSequenceGenerator(baos);
              seq.addObject(new ASN1Integer(1)); // version
              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);  // Cannot happen, writing to memory stream.
          }
      }
docs: Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by Bitcoin Core
  in its wallet storage format.
  @throws org.bitcoinj.core.ECKey.MissingPrivateKeyException if the private key is missing or encrypted.