title: What is the equivalent command in openssl to API of DES_ncbc_encrypt?
body: <p>Suppose I have this command in shell</p>
  
  <pre><code>&gt; echo -n "abc" | openssl enc -e -K 4a08805813ad4689 -iv 1112131415161718 -des-cbc -a -p -v
  salt=E0BE670000000000
  key=4A08805813AD4689
  iv =1112131415161718
  lb5mBZNE/nU=
  bytes read   :       3
  bytes written:      13
  
  &gt; echo -n "abc" | openssl enc -e -K 4a08805813ad4689 -iv fadced8beb69425b -des-cbc -a -p -v
  salt=E0BE670000000000
  key=4A08805813AD4689
  iv =FADCED8BEB69425B
  XXlljYbfJYg=
  bytes read   :       3
  bytes written:      13
  </code></pre>
  
  <p>and the c++ code</p>
  
  <pre><code>#include &lt;string.h&gt;
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  #include &lt;openssl/bio.h&gt;
  #include &lt;openssl/des.h&gt;
  #include &lt;openssl/evp.h&gt;
  
  int b64encode(char* in, int in_len, char* out, int out_cap_len);
  int b64decode(char* in, int in_len, char* out, int out_cap_len);
  int b64code(char* in, int in_len, char* out, int out_cap_len, bool way);
  
  int b64encode(char* in, int in_len, char* out, int out_cap_len)
  {
      return b64code(in, in_len, out, out_cap_len, true);
  }
  
  int b64decode(char* in, int in_len, char* out, int out_cap_len)
  {
      return b64code(in, in_len, out, out_cap_len, false);
  }
  
  int b64code(char* in, int in_len, char* out, int out_cap_len, bool way)
  {
      BIO* b64 = BIO_new(BIO_f_base64());
      BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
      BIO* bio = BIO_new(BIO_s_mem());
      BIO_push(b64, bio);
      int out_len = 0;
      if (way)
      {
          BIO_write(b64, in, in_len);
          BIO_flush(b64);
          out_len = BIO_read(bio, out, out_cap_len);
      }
      else
      {
          BIO_write(bio, in, in_len);
          BIO_flush(bio);
          out_len = BIO_read(b64, out, out_cap_len);
      }
      BIO_free_all(b64);
      return out_len;
  }
  
  void hexdump(unsigned char* ptr, int len)
  {
      for (int i = 0; i &lt; len; ++i)
      {
          printf("%02x", *(ptr + i));
      }
      printf("\n");
      return;
  }
  
  int main(int argc, char* argv[])
  {
      std::string text("abc");
      unsigned char cipher[1024] = "";
      DES_key_schedule schedule;
      DES_cblock key = { 0x4a, 0x08, 0x80, 0x58, 0x13, 0xad, 0x46, 0x89 };
      DES_cblock ivec = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 };
      DES_set_key_checked(&amp;key, &amp;schedule);
      printf("initialized:\n");
      printf("key=");
      hexdump(key, sizeof key);
      printf("iv =");
      hexdump(ivec, sizeof ivec);
      DES_ncbc_encrypt((unsigned char*)text.c_str(), cipher, (long)text.length(), &amp;schedule, &amp;ivec, DES_ENCRYPT);
      printf("updated:\n");
      printf("key=");
      hexdump(key, sizeof key);
      printf("iv =");
      hexdump(ivec, sizeof ivec);
      char b64encoded[1024] = "";
      b64encode((char*)cipher, strlen((char*)cipher), b64encoded, sizeof b64encoded - 1);
      std::cout &lt;&lt; b64encoded &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>Then I build and run it</p>
  
  <pre><code>&gt; g++ -o zdex.bex zdes.cpp -lcrypto &amp;&amp; ./zdex.bex
  initialized:
  key=4a08805813ad4689
  iv =1112131415161718
  updated:
  key=4a08805813ad4689
  iv =fadced8beb69425b
  +tzti+tpQls=
  </code></pre>
  
  <p>So if I want to get the identical result <code>+tzti+tpQls=</code> using <code>openssl</code> utility, how to change the way using it, do I need to change the endianness of <code>key</code> or <code>iv</code> or maybe the cipher name I don't know. Thanks in advance.</p>