Hello, I wanna help from any one. I need java encryption password what will be make by MD5 and UTF-8. I wrote some code when i run this program here show some error. Please check and give me full instruction because i m totally new on java programming.
Error:import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import sun.misc.BASE64Encoder; public final class MyPasswordEncrypt { public static synchronized String encrypt(String plaintext, String algorithm, String encoding) throws Exception { MessageDigest msgDigest = null; String hashValue = null; try { msgDigest = MessageDigest.getInstance(algorithm); msgDigest.update(plaintext.getBytes(encoding)); byte rawByte[] = msgDigest.digest(); hashValue = (new BASE64Encoder()).encode(rawByte); } catch (NoSuchAlgorithmException e) { System.out.println("No Such Algorithm Exists"); } catch (UnsupportedEncodingException e) { System.out.println("The Encoding Is Not Supported"); } return hashValue; } public static void main(String args[]) throws Exception { String plainPassword = "SecretPassword"; System.out.println("PlainText\tAlgo\tEncoding\tEncrypted Password"); System.out.println(plainPassword + "\tSHA\tUTF-8\t" + encrypt("MySecretPassword", "SHA", "UTF-8")); System.out.println(plainPassword + "\tSHA-1\tUTF-16\t" + encrypt("MySecretPassword", "SHA-1", "UTF-16")); System.out.println(plainPassword + "\tMD5\tUTF-8\t" + encrypt("MySecretPassword", "MD5", "UTF-8")); System.out.println(plainPassword + "\tMD5\tUTF-16\t" + encrypt("MySecretPassword", "MD5", "UTF-16")); } }
Main.java:7: class MyPasswordEncrypt is public, should be declared in a file named MyPasswordEncrypt.java
public final class MyPasswordEncrypt {
^
Main.java:5: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
import sun.misc.BASE64Encoder;
^
Main.java:16: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
hashValue = (new BASE64Encoder()).encode(rawByte);