What is the equivalent C# code of below Java code?
java.security.MessageDigest d = null;
d = java.security.MessageDigest.getInstance("SHA-1");
d.reset();
d.update(user_password.getBytes());
user_password = new String(d.digest());
user_password=user_password.replaceAll("\ufffd","?");
FYI... this code returns something likd ~£ž¹_WÁÞQAÐùß9Ã0Ï which I never done in C#.
Thanks in Advance !!!
Nirjana NPPosted Apr 21, 2017, 12:22 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 !!!