public IActionResult Signature([FromBody] SignatureModel model) { if (!ModelState.IsValid) { ApiData.code = 1005; ApiData.msg = ModelState.GetErrMsg(); return(Ok(ApiData)); } var settings = _settingService.GetMasterSettings(); if (String.IsNullOrEmpty(settings.OSSAccessKeyId) || String.IsNullOrEmpty(settings.OSSAccessKeyId)) { ApiData.code = 2001; ApiData.msg = "暂未开放上传操作"; return(Ok(ApiData)); } if (!settings.OSSAccessKeyId.Equals(model.AccessKeyId, StringComparison.InvariantCultureIgnoreCase)) { ApiData.code = 2001; ApiData.msg = "AccessKeyId错误"; return(Ok(ApiData)); } var signatureString = EncryptorHelper.HmacSha1(settings.OSSAccessKeySecret, $"{model.VERB}{model.ContentMD5}"); ApiData.code = 0; ApiData.msg = "获取成功"; ApiData.data = new { Signature = signatureString }; return(Ok(ApiData)); }
/// <summary> /// 验证签名 /// </summary> /// <param name="signature"></param> /// <param name="contentMD5"></param> /// <param name="VERB"></param> /// <returns></returns> private bool ValidSignature(string signature, string contentMD5, string VERB) { var settings = _settingService.GetMasterSettings(); string signatureString = EncryptorHelper.HmacSha1(settings.OSSAccessKeySecret, $"{VERB}{contentMD5}"); return(signatureString.Equals(signature, StringComparison.InvariantCultureIgnoreCase)); }