I have a PHP function. this code is to encryp a password
Is any one know how can I write this in Java code.
this what I was try but dont give me result.
byte[] rawSHA = null;
byte[] base64HexSHA = null;
MessageDigest md= null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
LOG.error("Unable to load MD5 Message Digest : " + e.getMessage(), e);
throw new IllegalStateException("MD5 Message Digest Instance Not Found");
}
rawSHA = md.digest(rawText.getBytes("UTF-8"));
base64HexSHA = Base64.encodeBase64(rawSHA);
System.out.println("result = "+base64HexSHA );
Thanks for help
EDIT : I use this for base64 library
import org.apache.tomcat.util.codec.binary.Base64;
I have Solved this. this may help for other.
String ps="tes";
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] encryptedPassword = md.digest(ps.getBytes());
byte[] encodedBytes = Base64.encodeBase64(encryptedPassword);
String Str2 = new String(encodedBytes);
give me a result :
before =tes
after :KLZi2IO212/Zbk3cXpungA