You can't really do that.
Drupal 8 hashes and salts the password on the server side.Both the form and the authentication API require the plain password which is then validated. You should use HTTPS to protect the password during submission.
To be able to do something like this, you'd either need to use encryption, so you can decrypt again on the server or bypass the API somehow, but that isn't really possible since Drupal's hashing implementation has a dynamic salt and each hash has its own salt that you do not know in JS. Also keep in mind that anyone can read/debug the JS and figure out your salt or encryption key if you have it in JS.