title: Need help converting encryption logic from Js to Java
body: <p>I am trying to re-create a code snippet from JS to Java, but the outputs are different. What am I doing wrong?
  This is the code snippet from JS:</p>
  <pre class="lang-js prettyprint-override"><code>var randomKey = 2116781760886580;
  
  var key = CryptoJS.enc.Utf8.parse(randomKey);
  
  var iv = CryptoJS.enc.Utf8.parse(randomKey);
  
  var encrypt = CryptoJS.AES
      .encrypt(CryptoJS.enc.Utf8.parse(&quot;Text to encrypt&quot;), key,
          {
              keySize: 128 / 8,
              iv: iv,
              mode: CryptoJS.mode.CBC,
              padding: CryptoJS.pad.Pkcs7
          });
  
  var out = btoa(encrypt);   //SGpJSWhDUXNmMEMzSk0vbmovaGZyQT09
  </code></pre>
  <p>The following is the Java code snippet:</p>
  <pre class="lang-java prettyprint-override"><code>String randomKey = &quot;2116781760886580&quot;;
  
  String plainText = &quot;Text to encrypt&quot;;
  
  byte[] keyBytes = randomKey.getBytes(StandardCharsets.UTF_8);
  
  Cipher cipher = Cipher.getInstance(&quot;AES/CBC/PKCS5Padding&quot;);
  
  IvParameterSpec ivSpec = new IvParameterSpec(keyBytes);
  
  SecretKeySpec sKey = new SecretKeySpec(keyBytes,&quot;AES&quot;);
  
  cipher.init(Cipher.ENCRYPT_MODE, sKey, ivSpec);
  
  byte[] encryptedBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
  
  String out = Base64.getEncoder().encodeToString(encryptedBytes);    //HjIIhCQsf0C3JM/nj/hfrA==
  </code></pre>