/// <summary> /// 对邮件内容进行签名,如果出错将返回错误 /// </summary> public Result <string> Sign(EMail_DKIM_RAW_EML eml) { var rtv = new Result <string>(); rtv.Value = ""; var body = eml.GetSignBody(true); var signHeadNames = eml.SelectSignHeaderNames(SignHeaderNames); var param = new List <string>(); param.Add("v=1"); param.Add("a=rsa-sha256"); param.Add("c=relaxed/relaxed"); param.Add("d=" + _EmailDomain); param.Add("s=" + _EmailSelector); param.Add("q=dns/txt"); param.Add("t=" + EMail_Unit.GetMS() / 1000); param.Add("h=" + signHeadNames.join(":")); param.Add("bh=" + Hash.SHA256.Base64(body)); param.Add("b="); var paramStr = param.join("; "); var signParams = eml.GetSignHeader(true, paramStr, null, signHeadNames); if (signParams.IsError) { signParams.errorTo(rtv); return(rtv); } rtv.Value = paramStr + _RSA.Sign("SHA256", signParams.Value); return(rtv); }
static private string GetRnd() { var now = EMail_Unit.GetMS(); if (now - UseTime > 30000) //30秒空闲更新一次 { lock (Lock) { now = EMail_Unit.GetMS(); if (now - UseTime > 30000) { Rnd = EMail_Unit.RandomStringMix(20); UseTime = now; } } } UseTime = now; return(Rnd); }