string KEY = "11111111";
int EXPIRATION = 60 * 60 * 24;
int ex = (int)Math.Floor((double)(GetTimeStamp(DateTime.Now) / 1000)) + EXPIRATION;
string url = "https:/imagedelivery.net?key="+ex;
var sha256 = new SHA256Managed();
var Asc = new UTF8Encoding();
var tmpByte = Asc.GetBytes(KEY);
var bufferToHex = sha256.ComputeHash(tmpByte);
sha256.Clear();
只会到这了,求大佬指点。
const string KEY = "YOUR_KEY_FROM_IMAGES_DASHBOARD"; const int EXPIRATION = 60 * 60 * 24; // 1 day string generateSignedUrl(string url) { // `url` is a full imagedelivery.net URL // e.g. https://imagedelivery.net/cheeW4oKsx5ljh8e8BoL2A/bc27a117-9509-446b-8c69-c81bfeac0a01/mobile var key = Encoding.UTF8.GetBytes(KEY); using var hmac = new HMACSHA256(key); // Attach the expiration value to the `url` var expiry = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + EXPIRATION; // `url` now looks like // https://imagedelivery.net/cheeW4oKsx5ljh8e8BoL2A/bc27a117-9509-446b-8c69-c81bfeac0a01/mobile?exp=1631289275 var stringToSign = $"{new Uri(url).AbsolutePath}?exp={expiry}"; // e.g. /cheeW4oKsx5ljh8e8BoL2A/bc27a117-9509-446b-8c69-c81bfeac0a01/mobile?exp=1631289275 // Generate the signature var mac = hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)); var sig = Convert.ToHexString(mac).ToLower(); // And attach it to the `url` return $"{url}?exp={expiry}&sig={sig}"; }
url 格式是这样。好像不太对。
// `url` now looks like
// https://imagedelivery.net/cheeW4oKsx5ljh8e8BoL2A/bc27a117-9509-446b-8c69-c81bfeac0a01/mobile?exp=1631289275