本文介绍了将Python中的SHA哈希计算转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 hash = hmac.new(secret, data,digestmod = hashlib.sha1) key = hash.hexdigest()[:8] #!/ usr / bin / env python 导入hmac 导入hashlib secret ='mySecret' data ='myData' hash = hmac。 new(secret,data,digestmod = hashlib.sha1) key = hash.hexdigest()[:8] 打印键 pre> 谢谢 解决方案您可以使用 HMACSHA1 类来计算哈希: class Program { static void Main() { var secret =secret; var data =data; var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(secret)); var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(data)); Console.WriteLine(BitConverter.ToString(hash)); } } Can someone please help me convert the following two lines of python to C#.hash = hmac.new(secret, data, digestmod = hashlib.sha1)key = hash.hexdigest()[:8]The rest looks like this if you're intersted:#!/usr/bin/env pythonimport hmacimport hashlibsecret = 'mySecret' data = 'myData'hash = hmac.new(secret, data, digestmod = hashlib.sha1)key = hash.hexdigest()[:8]print keyThanks 解决方案 You could use the HMACSHA1 class to compute the hash:class Program{ static void Main() { var secret = "secret"; var data = "data"; var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(secret)); var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(data)); Console.WriteLine(BitConverter.ToString(hash)); }} 这篇关于将Python中的SHA哈希计算转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 10:54