Demonstrates how to encrypt a string using the MD5 algorithm in Java. Since MD5 is non-reversable, there is no code for decrypting the value.
Contextual Ads
More Java Resources
Advertisement
- import java.math.*;
- import java.security.*;
- String toEnc = “Encrypt This!”; // Value to encrypt
- MessageDigest mdEnc = MessageDigest.getInstance(“MD5”); // Encryption algorithm
- mdEnc.update(toEnc.getBytes(), 0, toEnc.length());
- String md5 = new BigInteger(1, mdEnc.digest()).toString(16) // Encrypted string