0

I have problem converting the following Java code into toHexString and MessageDigest equivalent to C#.net code. I spend much time in converting them, but seems the result can never be the same.

Please help me especially in toHexString part.

import java.security.MessageDigest;
import java.util.Arrays;

public class Test
{
    public static void main(String[] args) throws Exception
    {
        String keyString = "01100880200013048720181107174008PC".toString();
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(keyString.getBytes("utf-8"));

        byte[] temp = md5.digest("".getBytes("utf-8"));

        String result = "";
        for (int i = 0; i < temp.length; ++i) {
            result = result + Integer.toHexString(0xFF & temp[i] | 0xFFFFFF00).substring(6);
        }
        System.out.println(result);
    }
}
2

1 Answer 1

1

You can get the hexadecimal string representation of an int by calling the .ToString("X2") method on it. Here is the documentation for more options.

To get the first 6 chars you can call the .SubString(0, 6) on the hex value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.