Example #1
0
        public void Load()
        {
            var s = PrivateKeySigner.LoadFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mycert.pem"));


            s.Sign(Encoding.Default.GetBytes("some text to sign."), SigningAlgorithm.RSASha1);
        }
Example #2
0
        private static void GetDkimSigners()
        {
            try
            {
                var files = new DirectoryInfo(Config.PrivateKeyFolder).GetFiles("*.pem");

                if (files.Length == 0)
                {
                    throw new Exception("No private key files (*.pem) found");
                }

                foreach (var file in files)
                {
                    var key      = file.Name.Replace(".pem", "");
                    var selector = key.Split('@')[0];
                    var domain   = key.Split('@')[1];

                    var pKeySig      = PrivateKeySigner.LoadFromFile(file.FullName);
                    var dkimSig      = new DkimSigner(pKeySig, domain, selector, new[] { "From", "To", "Subject" });
                    var domainKeySig = new DomainKeySigner(pKeySig, domain, selector, new[] { "From", "To", "Subject" });

                    dkimSig.HeaderCanonicalization = DkimCanonicalizationAlgorithm.RELAXED;
                    dkimSig.BodyCanonicalization   = DkimCanonicalizationAlgorithm.RELAXED;

                    _dkimSignerCache.TryAdd(key, dkimSig);
                    _domailKeySignerCache.TryAdd(key, domainKeySig);
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Warn("Unable to turn on DKIM: {0}", ex.Message);
            }
        }
        public void Load()
        {
            var tempFile = Path.GetTempFileName();

            File.WriteAllText(tempFile, PrivateKey);

            var s = PrivateKeySigner.LoadFromFile(tempFile);

            s.Sign(Encoding.Default.GetBytes("some text to sign."), SigningAlgorithm.RSASha1);
        }