0





401

Advertisement

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;
Question author Amor | Source

Advertisement


0


String someString = "qwe";
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
String checksum = new BigInteger(1, messageDigest.digest(someString.getBytes())).toString(16);
System.out.println(checksum);

Hope this helps .. :)

Answer author Amor