Posts

Showing posts with the label sha1

Convert ComputeHash using SHA1 algorithm in C# to Java

Convert ComputeHash using SHA1 algorithm in C# to Java 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; } just as side-note: SHA1 is no longer secure computerworld.com/article/3173616/security/… – M. Schena Jun 29 at 9:43 ...