MessageDigest code equivalent to C#


  • Hi all,

    What is the equivalent C# code for below Java code? d = null;
    d ="SHA-1");
    user_password = new String(d.digest());

    FYI... this code returns something likd ~£ž¹_WÁÞQAÐùß9Ã0Ï which I have never done in C#.

    Thanks in advance !!!

    • Edited by rmaharjan Friday, April 21, 2017 2:58 PM
    Friday, April 21, 2017 2:55 PM

All replies

  • Hi,

    You could look into below thread answer

    problem in converting java MD5 message digest hash into C# equivalent

    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Friday, April 21, 2017 3:42 PM

    I found the solution after spending more than 2 hours.

    Below is the equivalent code that gives the same result as above Java code.

    byte[] hashBytes = Encoding.UTF8.GetBytes(user_password);
    SHA1 sha1 = SHA1Managed.Create();
    byte[] cryptPassword = sha1.ComputeHash(hashBytes);
    user_password= Encoding.Default.GetString(cryptPassword);

    Thanks !!!


    Friday, April 21, 2017 4:21 PM
  • Hi rmaharjan,

    Thank you for posting here and sharing your solution.

    If your issue has been resolved, please remember to close your thread by marking useful posts as answer that can be helpful for other person with same issue.

    Best Regards,


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, April 24, 2017 8:54 AM