title: Java to Node.js AES/ECB/PKCS5Padding Encryption
body: <p>I have the following encrypt function in JAVA. I am trying to write the same encryption in Node.js using cipher from crypto. But, the output is not the same. It is using the same key and input.</p>
  <h3>JAVA</h3>
  <pre><code>public static String encrypt(String input, String key) {
      byte[] crypted = null;
      try {
          SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &quot;AES&quot;);
          Cipher cipher = Cipher.getInstance(&quot;AES/ECB/PKCS5Padding&quot;);
          cipher.init(Cipher.ENCRYPT_MODE, skey);
          crypted = cipher.doFinal(input.getBytes());
      } catch (Exception e) {
          System.out.println(e.toString());
      }
      String result = new String(Base64.encodeBase64(crypted));
      return result.replace(&quot;+&quot;, &quot;-&quot;);
  }
  </code></pre>
  <p>Sample output: 0HCkcjWj/PoCZ4ZUFJARs/m4kstigMFk8dQnT0uNhog= (44 characters)</p>
  <h3>Node.js</h3>
  <pre><code>encrypt = (input, key) =&gt; { 
      const algorithm = 'aes-128-cbc';   
      key = crypto.scryptSync(key, 'salt', 16);       
      const iv = Buffer.alloc(16, 0);
      const cipher = crypto.createCipheriv(algorithm, key, iv);
      cipher.setAutoPadding(true);
      let encrypted = cipher.update(input, 'utf8', 'base64');
      encrypted += cipher.final('base64');
      return encrypted.replace('+','-');
  }
  </code></pre>
  <p>Sample output: ZHtEbAhrIo7vWOjdMNgW6Q== (24 characters)</p>
  <p>Thanks in advance.</p>