title: Is there a way to cipher in java/kotlin and decipher in nodejs with AES/CBC?
body: <p>I try to cipher a text in java and decipher it in nodejs (and vice versa)</p>
  
  <p>I can cipher and decipher in the same language but I can't with them both ...</p>
  
  <p>Here is my code in Kotlin :</p>
  
  <pre><code>@Throws(Exception::class)
  fun encrypt(text: String, password: String?): String?
  {
      if (password == null)
          return null
  
      val hash = toHash(password).copyOf(16)
      val keySpec = SecretKeySpec(hash, "AES")
      val ivSpec = IvParameterSpec(hash)
      val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
      cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec)
  
      val results = cipher.doFinal(text.toByteArray())
  
      return Base64.encodeToString(results, Base64.NO_WRAP or Base64.DEFAULT)
  
  }
  
  @Throws(Exception::class)
  fun decrypt(text: String, password: String?): String?
  {
      if (password == null)
          return null
  
      val hash = toHash(password).copyOf(16)
      val keySpec = SecretKeySpec(hash, "AES")
      val ivSpec = IvParameterSpec(hash)
      val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
      cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec)
  
      return String(cipher.doFinal(Base64.decode(text, Base64.DEFAULT)))
  }
  </code></pre>
  
  <p>And here is my code in JS :</p>
  
  <pre><code>function decrypt(data, password)
  {
      var hash = sha256(password).substring(0, 16)
      var decipher = crypto.createDecipheriv('aes-128-cbc', hash, hash);
      var dec = decipher.update(data, 'hex', 'utf8');
      dec += decipher.final('utf8');
      return dec;
  }
  
  function encrypt(data, password)
  {
      var hash = sha256(password).substring(0, 16)
      var cipher = crypto.createCipheriv('aes-128-cbc', hash, hash);
      var crypted = cipher.update(data, 'utf8', 'hex');
      crypted += cipher.final('hex');
      return crypted;
  }
  </code></pre>
  
  <p>I have tried to play with the differents block size in Java and nodeJS (192, 128 and 256) but it's not working.
  I don't want to cipher in ECB, I want to achive this in CBC or CTR.</p>
  
  <p>Does someone know how to do this please ? Thank you per advance !</p>