Following is a code that will encrypts the user String :
import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.No
While old post here is an updated answer. Java 8's Base64.
Java 8 Base64 Documents