I have this code on C#:
public static string GenerateSecureHash(string data) {
HashAlgorithm algorithm = SHA1.Create();
byte[] hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(data));
StringBuilder sb = new StringBuilder();
foreach (byte b in hash)
sb.Append(b.ToString("x2"));
return sb.ToString();
}
Which generates an SHA1 String given a data
string. I tried converting this to Python3 with the following code:
def GenerateSecureHash(data: str):
print('Generate Secure Hash called!')
enc = str.encode('utf-8') # encode in utf8
hash = sha1(enc)
formatted = hash.hexdigest()
return formatted
But they give different outputs.
For example, if I feed in "testStringHere", here are the outputs:
C#: 9ae24d80c345695120ff1cf9a474e36f15eb71c9
Python: 226cf119b78825f1720cf2ca485c2d85113d68c6
Can anyone point me to the right direction?