title: Unknown cipher error when creating cipher using NodeJS
body: <p>I am converting the Java logic encryption to Node JS.</p>
  <p>My encryption key is 24 char base64 string as you see below. In java, it is decoded as byte[] and used for encryption. So in NodeJS, I don't know what is the best way to do it.
  But I am doing <code>Buffer.from(key, 'base64')</code> while creating the cipher. Is this correct? I am getting an <code>Unknown Cipher</code>. I tried with different algorithm modes. No luck.</p>
  <p><strong>Can someone please suggest which algorithm mode and IV key for creating cipher using 24 char base 64 string?</strong></p>
  <p>Would the cipher final value be the same between JAVA and NODE JS to make sure the conversion is correct before using the encryption URL?</p>
  <p>Java:</p>
  <pre><code>public class Encrypt {
  
  
      private Encrypt() {}
  
      public static String getURI() {
          String encryptedFinal = &quot;&quot;;
          String userId = &quot;userID&quot;;
          String pwd = &quot;aBEMxY2c/UWpoQFGSWSabD==&quot;; //24 chars long base64 key
          Date cDate = new Date();
          SimpleDateFormat simpledateformat = new SimpleDateFormat(&quot;yyyy-MM-dd'T'HH:mm:ss'Z'&quot;);
          simpledateformat.setTimeZone(TimeZone.getTimeZone(&quot;GMT&quot;));
  
          try
          {
              byte[] dBytes = simpledateformat.format(cDate).getBytes();
  
              byte[] bArray = Base64.decodeBase64(pwd.getBytes());
              SecretKeySpec keySpec = new SecretKeySpec(bArray, &quot;AES&quot;);
              System.out.println(simpledateformat.format(date).toString());
              Cipher cipher = Cipher.getInstance(&quot;AES&quot;);
              cipher.init(1, keySpec);
              byte[] cipher2 = cipher.doFinal(dBytes);
              byte[] cipher3 = cipher.doFinal(&quot;bloomberge.com/home&quot;.getBytes());
              encryptedFinal = &quot;http://bloomberge.com/&quot; + id + &quot;&amp;uri=&quot; +
                      Base64.encodeBase64String(cipher3) + &quot;&amp;date=&quot; +Base64.encodeBase64String(cipher2);
  
          }
          catch(Exception e)
          {
          System.out.println(e);
          }
          return encryptedFinal;
      }
  }
  </code></pre>
  <p>NodeJS:</p>
  <pre><code>const { createCipheriv } = require('crypto')
  const crypto = require('crypto')
  const userID = &quot;aBEMxY2c/UWpoQFGSWSabD==&quot;; //24 chars long base64 key
  
  const key = &quot;aBEMxY2c/UWpoQFGSWSabD==&quot;; //24 chars long base64 key
  const tDate = new Date().toISOString().split('.')[0] + 'Z'
  
  let cipher = createCipheriv('aes-128-ecm', Buffer.from(key, 'base64'), crypto.randomBytes(32)) //not sure if this is correct to read based 64 and how do I find correct iv length?. Getting the unknown cipher
  
  let myTime = cipher.update(tDate, 'utf8', 'base64')
  myTime += cipher.final('base64')
  
  let tURI = createCipheriv('aes-128-ecm', Buffer.from(key, 'base64'), crypto.randomBytes(32)) //same unknown cipher, 
  
  let tpURL = tURI.update(
      'bloomberg',
      'utf8',
      'base64'
  )
  tpURL += tURI.final('base64')
  
  return (
      'myweburl' +
      userId +
      '&amp;tURI=' +
      tpURL +
      '&amp;tDateTime=' +
      myTime)
  </code></pre>
  <p>Getting error at first cipher here</p>
  <pre><code>let cipher = createCipheriv('aes-128-ecm', Buffer.from(key, 'base64'), crypto.randomBytes(32))
  </code></pre>
  <p>Error message:</p>
  <blockquote>
  <p>{&quot;msg&quot;:&quot;Unknown cipher&quot;,&quot;stack&quot;:&quot;Error: Unknown cipher\n    at Cipheriv.createCipherBase (internal/crypto/cipher.js:103:19)\n    at Cipheriv.createCipherWithIV (internal/crypto/cipher.js:121:20)\n    at new Cipheriv (internal/crypto/cipher.js:227:22)\n    at createCipheriv (crypto.js:124:10)\n    at</p>
  </blockquote>