C#
## C# SDK
此sdk正在构建中,签名的源码如下:
```C#
using System;
using System.Security.Cryptography;
using System.Text;
namespace TCE
{
public static class Auth
{
//前缀
const string PREFIX = "TCE ";
//签名
public static string Sign(string ak, string sk)
{
//1.unix时间戳
DateTimeOffset dto = new DateTimeOffset(DateTime.UtcNow);
var unixTimes = dto.ToUnixTimeSeconds().ToString();
//2.使用sk进行HMAC-SHA256签名
var signed = HMACSHA256(unixTimes, sk);
//3.把PREFIX,AK,时间戳,sk组合成签名
var accessToken = $"{PREFIX}{ak}:{unixTimes}:{signed}";
return accessToken;
}
//hash处理
private static string HMACSHA256(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);
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
}
}
}
```