MD5 is an one-way encryption. You can't decrypt it back to the original string. It does also not make sense to do this in the view side. If you're using a database to store the data and your intent is to hash the passwords in the DB, then rather do this in the DB side. A bit decent DB offers functions for this. It's unclear which DB you're using, but in case of among others MySQL it's simply called md5()
.
Rewrite your INSERT
as follows:
String sql = "INSERT INTO user (username, password) VALUES (?, md5(?))";
And your SELECT
as follows:
String sql = "SELECT * FROM user WHERE username = ? AND password = md5(?)";
If your sole functional requirement is to encrypt the data transferred over HTTP (that wasn't clear from your question at all), then have a look for HTTPS (HTTP using SSL). This is configureable at webserver level. Again, it's unclear which one you're using, but in case of for example Tomcat, you can find detail in this documentation.