code: public static byte[] EncodePKCS8(byte[] algorithm, byte[] keyBytes, byte[] spki) throws CoseException
      {
          //  PKCS#8 ::= SEQUENCE {
          //     version INTEGER {0}
          //      privateKeyALgorithm SEQUENCE {
          //           algorithm OID,
          //           parameters ANY
          //      }
          //     privateKey ECPrivateKey,
          //     attributes [0] IMPLICIT Attributes OPTIONAL
          //     publicKey [1] IMPLICIT BIT STRING OPTIONAL
          //   }
          
          try {
  
            ArrayList<byte[]> xxx = new ArrayList<byte[]>();
              xxx.add(new byte[]{2, 1, 0});
              xxx.add(algorithm);
              xxx.add(OctetStringTag);
              xxx.add(ComputeLength(keyBytes.length));
              xxx.add(keyBytes);
  
              return Sequence(xxx);
          }
          catch (ArrayIndexOutOfBoundsException e) {
              System.out.print(e.toString());
              throw e;
          }
      }
docs: Encode a private key into a PKCS#8 private key structure.
  
  @param algorithm - EC curve OID
  @param keyBytes - raw bytes of the key
  @param spki - optional subject public key info structure to include
  @return byte array of encoded bytes
  @throws CoseException - ASN.1 encoding errors