Пример #1
0
        private string SignData(string data)
        {
            string sign;

            try
            {
                var encoding = Encoding.UTF8;
                var newdata  = encoding.GetBytes(data);
                var digest   = _skSpec.ComputeHash(newdata);
                sign = UrlSafeBase64.EncodeToString(digest);
            }
            catch (Exception e)
            {
                throw new Exception("Failed to generate HMAC : " + e.Message);
            }
            return(sign);
        }
Пример #2
0
        async Task <string> upload_firstChunk_fore(string uuid, PartViewStream pvs, long iblock, string uploadToken, string host, string keyname)
        {
            //const int block_size = 4 * 1024 * 1024;

            var            uploadUrl = host + $"/mkblk/{block_size}/{iblock}";
            HttpWebRequest req       = WebRequest.CreateHttp(uploadUrl);

            req.Method = "POST";
            //req.Headers.Add("Qingzhen-Token", recentToken);
            //req.Host = host;
            req.Headers.Add("Authorization", uploadToken);

            req.Headers.Add("UploadBatch", uuid);
            req.Headers.Add("Key", UrlSafeBase64.encode(keyname));
            req.ContentLength = pvs.Length;
            req.ContentType   = "application/octet-stream";
            var reqStream = await req.GetRequestStreamAsync();

            await pvs.CopyToAsync(reqStream);

            //pvs.BlockCopyTo(reqStream);
            reqStream.Close();
            var resp       = (HttpWebResponse)req.GetResponse();
            var respStream = resp.GetResponseStream();
            var sr         = new StreamReader(respStream);
            var retjson    = sr.ReadToEnd();

            sr.Close();
            resp.Close();
            req.Abort();
            Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(retjson);
            if (!json.ContainsKey("ctx"))
            {
                return(null);
            }
            return(json["ctx"].ToString());
        }
Пример #3
0
 public static string Sign(string secret, string data)
 {
     return(UrlSafeBase64.EncodeToString(Digest(secret, data)));
 }