Ejemplo n.º 1
0
        private string SignBody(string body)
        {
            var canonicalizer = new DkimCanonicalizer();
            var cb            = canonicalizer.CanonicalizeBody(body, BodyCanonicalization);

            var bytes = Encoding.GetBytes(cb);

            if (SigningAlgorithm != DkimSigningAlgorithm.RSASha256)
            {
                throw new InvalidOperationException();
            }

            return(Convert.ToBase64String(SHA256.Hash(bytes)));
        }
Ejemplo n.º 2
0
        private string SignHeaders(MailHeader[] headers, MailHeader dkimHeader)
        {
            if (headers == null || headers.Length == 0)
            {
                throw new ArgumentException("headers");
            }

            var canonicalizer = new DkimCanonicalizer();
            var ch            = canonicalizer.CanonicalizeHeaders(
                headers.Union(new[] { dkimHeader }).ToArray(),
                HeaderCanonicalization);

            if (SigningAlgorithm != DkimSigningAlgorithm.RSASha256)
            {
                throw new NotImplementedException();
            }

            var data = Encoding.GetBytes(ch.TrimEnd());

            return(Convert.ToBase64String(RSA.Sign(data, privateKey)));
        }