Created
July 15, 2018 06:23
-
-
Save saisankargochhayat/266ab9c25793eb860940177ddf631ced to your computer and use it in GitHub Desktop.
Get HMAC SHA256 for Shyplite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.Security.Cryptography; | |
namespace ConsoleApp1 | |
{ | |
class Auth | |
{ | |
public String GetHash(String text, String key) | |
{ | |
ASCIIEncoding encoding = new ASCIIEncoding(); | |
Byte[] textBytes = encoding.GetBytes(text); | |
Byte[] keyBytes = encoding.GetBytes(key); | |
Byte[] hashBytes; | |
using (HMACSHA256 hash = new HMACSHA256(keyBytes)) | |
hashBytes = hash.ComputeHash(textBytes); | |
String.Concat(Array.ConvertAll(hashBytes, x => x.ToString("x2"))); | |
// to base64 | |
return (Uri.EscapeDataString(Convert.ToBase64String(hashBytes))); | |
} | |
static void Main(string[] args) | |
{ | |
DateTime foo = DateTime.UtcNow; | |
long unixTime = ((DateTimeOffset)foo).ToUnixTimeSeconds(); | |
string appId = "1129"; | |
string key = "NIZePNJ4BBc="; | |
string secret = "1hezif2aqq+mTxVe1LFNJbW4nWQ13YF9x/jEEKmHBVFRiiWzQTHXtsXS02B/TABs0kEEIsjb8CBdTbraXMGyPA=="; | |
string hash = "key:5nF6Ai4ykPY=id:1:timestamp:1500000000000"; | |
Auth token = new Auth(); | |
string result = token.GetHash(hash, secret); | |
Console.WriteLine(result); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment