How to use evaluateJavascript in WebView
<p>I need to encrypt a password before logging in. 
The encryption code is in javascript</p>

<pre><code>function encrypt(password) {
    var modulus = "00b6b7f8531b19980c66ae08e3061c6295a1dfd9406b32b202a59737818d75dea03de45d44271a1473af8062e8a4df927f031668ba0b1ec80127ff323a24cd0100bef4d524fdabef56271b93146d64589c9a988b67bc1d7a62faa6c378362cfd0a875361ddc7253aa0c0085dd5b17029e179d64294842862e6b0981ca1bde29979";
    var exponent = "010001";
    var key = RSAUtils.getKeyPair(exponent,"", modulus);
    return RSAUtils.encryptedString(key, password);
}
</code></pre>

<p>the functions RSAUtils are defined earlier. (I tried this on Chrome and it worked).</p>

<p>I tried</p>

<pre><code>WebView encryptor = (WebView) findViewById(R.id.encryptor);
encryptor.getSettings().setJavaScriptEnabled(true);
encryptor.loadUrl("file:///android_asset/encryption.html");
encryptor.evaluateJavascript("encrypt(\"" + password + "\" )", new ValueCallback&lt;String&gt;() {
    @Override
    public void onReceiveValue(String s) {
        Log.d("encrypted password", s);
    }
});
</code></pre>

<p>and got </p>

<pre><code>I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: encrypt is not defined", source:  (1)
</code></pre>

<p>and</p>

<pre><code>D/encrypted password: null
</code></pre>

<p>in logcat.</p>

<p>I tried to load html in a <code>WebView</code> and it was loaded correctly.</p>

<p>Does anyone know where this goes wrong?</p>