Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        /// <summary>
        /// 用一个手写的key获取header里面的内容,因为header里面的key是什么样的完全无法知晓。
        /// </summary>
        public string GetHeader(string key)
        {
            var keysMp = FixedHeaderLowerKeys;

            return(EMail_Unit.STR(_Headers[keysMp.getString(key.ToLower())]));
        }
Пример #4
0
 /// <summary>
 /// Hash Base64
 /// </summary>
 public string Base64(byte[] byts)
 {
     return(EMail_Unit.Base64EncodeBytes(Bytes(byts)));
 }