I have a function to encrypt a string with the SHA1 algorithm in C#. And now I would like to convert exactly it to Java language. I have tried, but I don't get the same output for C# and Java.
Someone kindly please help me convert it. I'm really grateful for this. Thanks.
Here is C# code :
public static string ComputeHash(string inString) {
SHA1 sh = SHA1.Create();
byte[] data = UTF8Encoding.UTF8.GetBytes(inString);
byte[] result = sh.ComputeHash(data);
return ToHexString(result);
}
public static string ToHexString(byte[] data) {
string s = "";
for (int i = 0, n = data.Length; i < n; i++) {
s += String.Format("{0:X2}", data[i]);
}
return s;
}