0 Replies Latest reply on Jul 28, 2020 11:50 PM by 7c7ecf14-1aee-4102-9dac-af04ec88fd6c

    Hi There, Is it possible to convert a Java Code into Javascript code?

    7c7ecf14-1aee-4102-9dac-af04ec88fd6c

      Hi There,

       

      i have a Java code for Generating Encryption Key and I would like it to be in Javascript code, please help.

       

      package encrypt;

       

      import org.apache.commons.codec.binary.Base64;

      import javax.crypto.Cipher;

      import java.io.UnsupportedEncodingException;

      import java.security.NoSuchAlgorithmException;

      import java.util.Arrays;

       

      import java.security.Key;

      import java.security.MessageDigest;

      import javax.crypto.spec.SecretKeySpec;

       

       

      public class AESEncryptor

      {

          private static SecretKeySpec secretKey;

          private static byte[] key;

          private static String key1;

         

          public static void setKey(final String myKey, final int iterations) {

              AESEncryptor.key1 = myKey.toString();

              MessageDigest sha = null;

              try {

                  AESEncryptor.key = myKey.getBytes("UTF-8");

                  sha = MessageDigest.getInstance("SHA-256");

                  for (int i = 1; i <= iterations; ++i) {

                      AESEncryptor.key = sha.digest(AESEncryptor.key);

                  }

                  AESEncryptor.key = Arrays.copyOf(AESEncryptor.key, 16);

                  AESEncryptor.secretKey = new SecretKeySpec(AESEncryptor.key, "AES");

              }

              catch (NoSuchAlgorithmException e) {

                  e.printStackTrace();

              }

              catch (UnsupportedEncodingException e2) {

                  e2.printStackTrace();

              }

          }

      }