title: Decrypt OpenSSL encrypted data using java
body: <p>I am trying to understand OpenSSL encryption. The requirement for me is to decrypt the data encrypted using the below code. It is creating an anonymous ID for receiver. I need to get received ID back.</p>
  
  <p>Based on the documentation I understood encryption is happening using <code>EVP_EncryptFinal</code>. But what is <code>PKCS5_PBKDF2_HMAC_SHA1</code> doing ?</p>
  
  <p>The code is using KEY and IV.</p>
  
  <pre><code>int create_anon_id(uint32_t recvr_id, uint32_t smartcard_id, const char *hw_id, unsigned char *anon_id)
  {
      EVP_CIPHER_CTX ctx;
      unsigned char ibuf[sizeof(recvr_id) + sizeof(smartcard_id)] = {};
      unsigned char obuf[sizeof(ibuf) * 2] = {};
      int olen = sizeof(obuf);
  
      /* Convert to big endian. */
      recvr_id = bswap32(recvr_id);
      smartcard_id = bswap32(smartcard_id);
      hw_id = bswap32(hw_id);
  
      /* Fill input buffer with recvr_id | smartcard_id */
      memcpy(ibuf, &amp;recvr_id, sizeof(recvr_id));
      memcpy(ibuf + sizeof(recvr_id), &amp;smartcard_id, sizeof(smartcard_id));
  
      if (EVP_EncryptInit(&amp;ctx, EVP_des_ede3_cbc(), KEY, IV) == 1)
      {
          if (EVP_EncryptUpdate(&amp;ctx, obuf, &amp;olen, ibuf, sizeof(ibuf)) == 1)
          {
              olen = sizeof(obuf) - olen;
              if (EVP_EncryptFinal(&amp;ctx, obuf + sizeof(obuf) - olen, &amp;olen) == 1)
              {
                  return PKCS5_PBKDF2_HMAC_SHA1((const char *)obuf, olen, (unsigned char *)hw_id, HW_ID_SIZE, ROUNDS, ANON_ID_BIN_SIZE, anon_id);
              }
          }
      }
  }
  </code></pre>