title: Determining attributes of flutter encrypt.dart
body: <p>I am using <a href="https://pub.dev/packages/encrypt" rel="nofollow noreferrer">encrypt.dart</a> to AES encrypt a string (&quot;text&quot;) based on a 32 digit password (&quot;password&quot;) as follows:</p>
  <pre><code>encryptPass(String text, String password) {
     final key = getKey(password);
     final iv = encrypt.IV.fromLength(16);
     final encrypter = encrypt.Encrypter(encrypt.AES(key)); //Uses AES/SIC/PKCS7
     final e = encrypter.encrypt(text, iv: iv);
     String encryptedString = e.base64.toString();
     return encryptedString;
  }
  
   getKey(String masterPass) {
     String keyString = masterPass;
     if (keyString.length &lt; 32) {
       int count = 32 - keyString.length;
       for (var i = 0; i &lt; count; i++) {
         keyString += &quot;.&quot;;
       }
     }
     final keyReturn = encrypt.Key.fromUtf8(keyString);
     return keyReturn;
   }
  </code></pre>
  <p>Side note: This works, but it produces the same value every time for a given input string, even though my &quot;iv&quot; and &quot;salt&quot; are supposedly random. How does this happen?</p>
  <p><strong>MAIN PROBLEM:</strong> I am trying to recreate this process using spongy castle in kotlin. The problem is that I don't know certain important attributes of the encrypt.dart AES functions. What values are used for:</p>
  <p><strong>salt length:</strong> 16, 32, 128, 256?? (&quot;desiredKeyLength&quot; var in encrypted.dart. not specified anywhere)
  <strong>iteration count:</strong> (I think this is 100, but I am not certain.)
  <strong>Secret Key algorithm:</strong> I assumed PBKDF2WithHmacSHA1 based on &quot;final pbkdf2&quot; of encrypted.dart.
  <strong>key length:</strong> ?</p>
  <p>Here is my current attempt at <a href="https://github.com/rtyley/spongycastle" rel="nofollow noreferrer">spongy castle</a> implementation for reference:</p>
  <pre><code>fun encryptAESBasic(input: String, password: String): String {
      Security.insertProviderAt(org.spongycastle.jce.provider.BouncyCastleProvider(), 1)
      val masterpw = password.toCharArray()
      val random = SecureRandom()
      val salt = ByteArray(256)
      random.nextBytes(salt)
      val factory: SecretKeyFactory = SecretKeyFactory.getInstance(&quot;PBKDF2WithHmacSHA1&quot;)
      val spec: KeySpec = PBEKeySpec(masterpw, salt, 100, 128)
      val tmp: SecretKey = factory.generateSecret(spec)
      val key: SecretKey = tmp
      val cipher = Cipher.getInstance(&quot;AES/SIC/PKCS7PADDING&quot;, &quot;SC&quot;)
      val iv = ByteArray(16)
      SecureRandom().nextBytes(iv)
      cipher.init(Cipher.ENCRYPT_MODE, key, IvParameterSpec(iv))
      val cipherText: ByteArray = cipher.doFinal(input.toByteArray())
      return cipherText.toString()
  }
  </code></pre>