本文整理汇总了C#中System.Security.Cryptography.HMACSHA1.ToHex方法的典型用法代码示例。如果您正苦于以下问题:C# HMACSHA1.ToHex方法的具体用法?C# HMACSHA1.ToHex怎么用?C# HMACSHA1.ToHex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.HMACSHA1
的用法示例。
在下文中一共展示了HMACSHA1.ToHex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Hook
public ActionResult Hook()
{
var eventType = Request.Headers["X-Github-Event"];
var signature = Request.Headers["X-Hub-Signature"].Substring(5);
var ms = new MemoryStream();
Request.InputStream.CopyTo(ms);
byte[] data = ms.ToArray();
var secretKey = new Secrets().GetGithubHookKey(new ZkDataContext());
var hash = new HMACSHA1(Encoding.ASCII.GetBytes(secretKey)).ComputeHash(data);
if (!string.Equals(hash.ToHex(), signature, StringComparison.InvariantCultureIgnoreCase)) return Content("Signature does not match");
dynamic payload = JObject.Parse(Encoding.UTF8.GetString(data));
string text = null;
Object[] values;
switch (eventType) {
case "issues":
values = new [] {payload.repository.name ,payload.sender.login, payload.action, payload.issue.title, payload.issue.html_url};
text = string.Format("[{0}] {1} has {2} issue {3} {4}",values);
break;
case "pull_request":
values = new [] {payload.repository.name ,payload.sender.login, payload.action, payload.number, payload.pull_request.title , payload.pull_request.html_url, payload.pull_request.body};
text = string.Format("[{0}] {1} has {2} pull request #{3}: {4} ( {5} )\n{6}",values);
break;
case "push":
var sb = new StringBuilder();
int count = 0;
dynamic commits = payload.commits;
foreach (dynamic commit in commits)
{
sb.AppendFormat("\n {0} ( {1} )", commit.message, commit.url);
count++;
}
if (count > 0) text = $"[{payload.repository.name}] {payload.sender.login} has pushed {count} commits: {sb}";
break;
}
if (text != null) Global.Server.GhostChanSay("zkdev", text);
return Content("");
}
示例2: Hook
public ActionResult Hook()
{
var eventType = Request.Headers["X-Github-Event"];
var signature = Request.Headers["X-Hub-Signature"].Substring(5);
var ms = new MemoryStream();
Request.InputStream.CopyTo(ms);
byte[] data = ms.ToArray();
var secretKey = new Secrets().GetGithubHookKey(new ZkDataContext());
var hash = new HMACSHA1(Encoding.ASCII.GetBytes(secretKey)).ComputeHash(data);
if (!string.Equals(hash.ToHex(), signature, StringComparison.InvariantCultureIgnoreCase)) return Content("Signature does not match");
dynamic payload = JObject.Parse(Encoding.UTF8.GetString(data));
string text = null;
Object[] values;
switch (eventType) {
case "issues":
values = new [] {payload.repository.name ,payload.sender.login, payload.action, payload.issue.title, payload.issue.html_url};
text = string.Format("[{0}] {1} has {2} issue {3} {4}",values);
break;
case "pull_request":
values = new [] {payload.repository.name ,payload.sender.login, payload.action, payload.number, payload.pull_request.title , payload.pull_request.html_url};
text = string.Format("[{0}] {1} has {2} pull request #{3}: {4} ({5})",values);
break;
}
if (text != null) Global.Nightwatch.Tas.Say(SayPlace.Channel, "zkdev", text, true);
return Content("");
}