我有一個小型的C#函數,我想在Python中使用它。但我不知道如何使用hashlib來實現相同的結果。該函數接收一個字符串的返回字符串的SHA1哈希的base64編碼:將字符串轉換爲sha1中的基礎64 Python中的哈希
private string ConvertStringToHash(string word)
{
return Convert.ToBase64String(new SHA1CryptoServiceProvider().ComputeHash(new UnicodeEncoding().GetBytes(word)));
}
我想這對蟒蛇,但林沒有得到相同的結果:
def convert_string_to_hash(word):
m1 = hashlib.sha1()
m1.update(word)
res = m1.digest()
encoded = base64.b64encode(res)
return encoded
最新最好的辦法在Python中完成同樣的事情?
你可以發佈一些示例輸入詞和你的預期輸出嗎? – randomir