public static ByteArrayOutputStream writeCpabeData(byte[] mBuf,
            byte[] cphBuf, byte[] aesBuf) throws IOException {
        int i;
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        /* write m_buf */
        for (i = 3; i >= 0; i--) {
            os.write(((mBuf.length & (0xff << 8 * i)) >> 8 * i));
        }
        os.write(mBuf);

        /* write aes_buf */
        for (i = 3; i >= 0; i--) {
            os.write(((aesBuf.length & (0xff << 8 * i)) >> 8 * i));
        }
        os.write(aesBuf);

        /* write cph_buf */
        for (i = 3; i >= 0; i--) {
            os.write(((cphBuf.length & (0xff << 8 * i)) >> 8 * i));
        }
        os.write(cphBuf);

        os.close();
        return os;
    }