blog / 2019 /07 /02 /encmail.html
User Mayx
update
2026b8b
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Begin Jekyll SEO tag v2.8.0 -->
<title>制作分布式加密邮件系统的计划 | Mayx的博客</title>
<meta name="generator" content="Jekyll v3.9.5" />
<meta property="og:title" content="制作分布式加密邮件系统的计划" />
<meta name="author" content="mayx" />
<meta property="og:locale" content="zh_CN" />
<meta name="description" content="一个计划还没开始,又开始另一个计划了……" />
<meta property="og:description" content="一个计划还没开始,又开始另一个计划了……" />
<meta property="og:site_name" content="Mayx的博客" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2019-07-02T00:00:00+08:00" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="制作分布式加密邮件系统的计划" />
<meta name="google-site-verification" content="huTYdEesm8NaFymixMNqflyCp6Jfvd615j5Wq1i2PHc" />
<meta name="msvalidate.01" content="0ADFCE64B3557DC4DC5F2DC224C5FDDD" />
<meta name="yandex-verification" content="fc0e535abed800be" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"BlogPosting","author":{"@type":"Person","name":"mayx"},"dateModified":"2019-07-02T00:00:00+08:00","datePublished":"2019-07-02T00:00:00+08:00","description":"一个计划还没开始,又开始另一个计划了……","headline":"制作分布式加密邮件系统的计划","mainEntityOfPage":{"@type":"WebPage","@id":"/2019/07/02/encmail.html"},"publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"https://avatars0.githubusercontent.com/u/17966333"},"name":"mayx"},"url":"/2019/07/02/encmail.html"}</script>
<!-- End Jekyll SEO tag -->
<link rel="canonical" href="https://mabbs.github.io/2019/07/02/encmail.html" />
<link type="application/atom+xml" rel="alternate" href="/atom.xml" title="Mayx的博客" />
<link rel="alternate" type="application/rss+xml" title="Mayx的博客(RSS)" href="/rss.xml" />
<link rel="alternate" type="application/json" title="Mayx的博客(JSON Feed)" href="/feed.json" />
<link rel="stylesheet" href="/assets/css/style.css?v=1764518410" />
<!--[if !IE]> -->
<link rel="stylesheet" href="/Live2dHistoire/live2d/css/live2d.css" />
<!-- <![endif]-->
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Mayx的博客" />
<link rel="webmention" href="https://webmention.io/mabbs.github.io/webmention" />
<link rel="pingback" href="https://webmention.io/mabbs.github.io/xmlrpc" />
<link rel="preconnect" href="https://summary.mayx.eu.org" crossorigin="anonymous" />
<link rel="prefetch" href="https://www.blogsclub.org/badge/mabbs.github.io" as="image" />
<link rel="blogroll" type="text/xml" href="/blogroll.opml" />
<link rel="me" href="https://github.com/Mabbs" />
<script src="/assets/js/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.3/jquery.xdomainrequest.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
var lastUpdated = new Date("Mon, 01 Dec 2025 00:00:10 +0800");
var BlogAPI = "https://summary.mayx.eu.org";
</script>
<script src="/assets/js/main.js"></script>
<!--[if !IE]> -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-137710294-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-137710294-1');
</script>
<script src="/assets/js/instant.page.js" type="module"></script>
<!-- <![endif]-->
</head>
<body>
<!--[if !IE]> --><noscript><marquee style="top: -15px; position: relative;"><small>发现当前浏览器没有启用JavaScript,这不影响你的浏览,但可能会有一些功能无法使用……</small></marquee></noscript><!-- <![endif]-->
<!--[if IE]><marquee style="top: -15px; position: relative;"><small>发现当前浏览器为Internet Explorer,这不影响你的浏览,但可能会有一些功能无法使用……</small></marquee><![endif]-->
<div class="wrapper">
<header class="h-card">
<h1><a class="u-url u-uid p-name" rel="me" href="/">Mayx的博客</a></h1>
<img src="https://avatars0.githubusercontent.com/u/17966333" fetchpriority="high" class="u-photo" alt="Logo" style="width: 90%; max-width: 300px; max-height: 300px;" />
<p class="p-note">Mayx's Home Page</p>
<form action="/search.html">
<input type="text" name="keyword" id="search-input-all" placeholder="Search blog posts.." />&#160;<input type="submit" value="搜索" />
</form>
<br />
<p class="view"><a class="u-url" href="/Mabbs/">About me</a></p>
<ul class="downloads">
<li style="width: 270px; border-right: none;"><a href="/MayxBlog.tgz">Download <strong>TGZ File</strong></a></li>
</ul>
</header>
<section class="h-entry">
<small><time class="date dt-published" datetime="2019-07-02T00:00:00+08:00">2 July 2019</time> - 字数统计:1387 - 阅读大约需要5分钟 - Hits: <span id="/2019/07/02/encmail.html" class="visitors">Loading...</span></small>
<h1 class="p-name">制作分布式加密邮件系统的计划</h1>
<p class="view">by <a class="p-author h-card" href="//github.com/Mabbs">mayx</a></p>
<div id="outdate" style="display:none;">
<hr /><p>
这是一篇创建于 <span id="outime"></span> 天前的文章,其中的信息可能已经有所发展或是发生改变。
</p>
</div>
<script>
daysold = Math.floor((new Date().getTime() - new Date("Tue, 02 Jul 2019 00:00:00 +0800").getTime()) / (24 * 60 * 60 * 1000));
if (daysold > 90) {
document.getElementById("outdate").style.display = "block";
document.getElementById("outime").innerHTML = daysold;
}
</script>
<hr />
<b>AI摘要</b>
<p id="ai-output">这篇文章的计划是制作一个分布式加密邮件系统,起因是对Telegram的私密通信功能的兴趣,尤其是其在中国的使用限制。作者打算用HTML、Javascript、PHP和MySQL构建这个系统,选择PHP是因为其易于搭建且常见。项目将采用非对称加密(RSA)和对称加密(AES)相结合的方式,确保在客户端进行加密,以保护隐私。系统设计包括用户通过注册获得公钥,使用公钥和私钥进行登录验证,邮件发送时会通过多个节点尝试连接,确保安全性。然而,作者提到如果服务器被攻陷,公钥被篡改可能导致问题,尤其是对于不熟悉技术的用户。文章最后以一个轻松的语气提问项目的启动时间。</p>
<hr />
<ul><li><a href="#计划原因">计划原因</a><ul><li><a href="#qa">Q&amp;A</a></li></ul></li><li><a href="#项目技术原理">项目技术原理</a></li><li><a href="#项目细节">项目细节</a></li><li><a href="#问题">问题</a></li></ul>
<hr />
<main class="post-content e-content" role="main"><p>一个计划还没开始,又开始另一个计划了……<!--more--></p>
<h1 id="计划原因">
<a href="#计划原因"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> 计划原因
</h1>
<p>之前用了Telegram聊天,里面有一个私密通信的功能。听说这个功能可以让服务端没法知道使用者发送的信息。不过Telegram在国内使用限制比较多,所以我打算用HTML+Javascript+PHP+MySQL写一套自己的私密通信系统。 </p><p>
但是As We All Know,某些国家有网络审查,提供这种服务的肯定会被审查的。既然我们要做这个东西,就不能让它不稳定。所以我想把这个项目搞成分布式的那种,确保通信可以成功。(来自Mastodon的思路)</p>
<h2 id="qa">
<a href="#qa"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> Q&amp;A
</h2>
<ol>
<li>为什么使用PHP? </p><p>
之所以用PHP作为后端语言的原因呢…… <del>当然因为PHP是世界上最好的语言!(被打死)</del> 因为PHP的程序好搭建,而且很多虚拟主机商都用的是PHP,这样即使小白也能搭建,就能让分布式节点更多了。 <del>(明明主要原因是我只会PHP 23333)</del></li>
<li>为什么我要做成邮件系统而不是聊天系统呢? </p><p>
因为聊天就要用Websocket或者是AJAX之类的,但是我不会……我只能把信息都存在服务器里,有人访问再显示出来……</li>
<li>已经有PGP了,为什么还要重复造轮子呢? </p><p>
因为PGP是软件,小白用起来不太方便,这个是网站,可能相对更简单一些。 <del>(重复造轮子能有什么理由)</del></li>
</ol>
<h1 id="项目技术原理">
<a href="#项目技术原理"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> 项目技术原理
</h1>
<ol>
<li>所谓的私密通信主要用的就是非对称加密,比如说RSA什么的。所以这个项目同样如此,也使用RSA作为主要加密算法。</li>
<li>RSA虽然很不错,但是似乎加密速度比较慢?(我看HTTPS上介绍的是这样)所以内容用AES加密,用随机数做密码,一方用公钥去加密这个密码,另一方用私钥解密获得密码,然后再利用这个密码进行对称加密传输(和HTTPS差不多)。</li>
<li>如果上述操作都是服务端进行,那这些就都没什么意义了,所以我们要在客户端进行。像Javascript进行加密完全没有问题,所以除了传输,其他加密都是在浏览器上进行。</li>
</ol>
<h1 id="项目细节">
<a href="#项目细节"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> 项目细节
</h1>
<p>为了方便通信,公钥是要留在服务器上的,所以要搞一个用户系统,存储用户的公钥。在注册的过程中公私钥生成都是在客户端进行,确保服务端得不到用户的私钥,注册的过程中要将用户名和公钥上传至服务器保存。这就是为什么要用到MySQL。 </p><p>
登录时,先输入用户名,服务器使用用户名查找到对应的公钥,然后生成一个随机数,用公钥加密,发送给客户端,客户端用私钥解密,获得随机数,返回给服务器进行登录。 </p><p>
私钥登录后要持续保存,这时肯定不能用Cookie,我们可以用localStorage,然后客户端一定要做好防XSS,不然一切都没有了。 </p><p>
在发送的时候,我们可以搞一个类似Mastodon的用户名,两个@实在是太蠢了,就和E-mail一样,就搞成user@example.com的形式吧 </p><p>
在发送时客户端先检查对方服务器能否连接,如不能则测试通过服务器连接,如果服务器连接失败再使用其他节点连接(服务器内置),如果还是不行,用户可以自行输入节点,还是不行,投递失败。 </p><p>
连接成功后对方服务器查询对应用户的公钥,返回给客户端,客户端用这个公钥加密AES密码,用AES密码加密内容,然后再传给对方服务器保存。 </p><p>
查看邮件就用私钥解密AES密码,然后解密内容。</p>
<h1 id="问题">
<a href="#问题"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> 问题
</h1>
<p>如果对方服务器被攻陷,公钥被改成攻击者的,那不就没用了吗?虽然可以用指纹解决,但是这对小白来说似乎有些困难……HTTPS用的是第三方权威解决这个问题,我们就没办法了…… </p><p>
最大的问题是,什么时候开始动工?(笑)</p></main>
<small style="display: block">tags: <a rel="category tag" class="p-category" href="/search.html?keyword=%E5%88%86%E5%B8%83%E5%BC%8F"><em>分布式</em></a> - <a rel="category tag" class="p-category" href="/search.html?keyword=%E5%8A%A0%E5%AF%86"><em>加密</em></a> - <a rel="category tag" class="p-category" href="/search.html?keyword=%E9%82%AE%E4%BB%B6"><em>邮件</em></a> - <a rel="category tag" class="p-category" href="/search.html?keyword=%E8%AE%A1%E5%88%92"><em>计划</em></a> <span style="float: right;"><a href="https://gitlab.com/mayx/mayx.gitlab.io/tree/master/_posts/2019-07-02-encmail.md">查看原始文件</a></span></small>
<h4 style="border-bottom: 1px solid #e5e5e5;margin: 2em 0 5px;">推荐文章</h4>
<p id="suggest-container">Loading...</p>
<script>
var suggest = $("#suggest-container");
$.get(BlogAPI + "/suggest?id=/2019/07/02/encmail.html&update=" + lastUpdated.valueOf(), function (data) {
if (data.length) {
getSearchJSON(function (search) {
suggest.empty();
var searchMap = {};
for (var i = 0; i < search.length; i++) {
searchMap[search[i].url] = search[i];
}
var tooltip = $('<div class="content-tooltip"></div>').appendTo('body').hide();
for (var j = 0; j < data.length; j++) {
var item = searchMap[data[j].id];
if (item) {
var link = $('<a href="' + item.url + '">' + item.title + '</a>');
var contentPreview = item.content.substring(0, 100);
if (item.content.length > 100) {
contentPreview += "……";
}
link.hover(
function(e) {
tooltip.text($(this).data('content'))
.css({
top: e.pageY + 10,
left: e.pageX + 10
})
.show();
},
function() {
tooltip.hide();
}
).mousemove(function(e) {
tooltip.css({
top: e.pageY + 10,
left: e.pageX + 10
});
}).data('content', contentPreview);
suggest.append(link);
suggest.append(' - ' + item.date + '<br />');
}
}
});
} else {
suggest.html("暂无推荐文章……");
}
});
</script>
<br />
<div class="pagination">
<span class="prev">
<a href="/2019/07/01/mabbs.html">
上一篇:重建MaBBS的计划
</a>
</span>
<br />
<span class="next">
<a href="/2019/07/15/encmail.html">
下一篇:EncMail-Project Part 1 - 准备阶段
</a>
</span>
</div>
<!--[if !IE]> -->
<link rel="stylesheet" href="/assets/css/gitalk.css">
<script src="/assets/js/gitalk.min.js"></script>
<div id="gitalk-container"></div>
<script>
var gitalk = new Gitalk({
clientID: '36557aec4c3cb04f7ac6',
clientSecret: 'ac32993299751cb5a9ba81cf2b171cca65879cdb',
repo: 'mabbs.github.io',
owner: 'Mabbs',
admin: ['Mabbs'],
id: '/2019/07/02/encmail', // Ensure uniqueness and length less than 50
distractionFreeMode: false, // Facebook-like distraction free mode
proxy: "https://cors-anywhere.mayx.eu.org/?https://github.com/login/oauth/access_token"
})
gitalk.render('gitalk-container')
</script>
<!-- <![endif]-->
</section>
<!--[if !IE]> -->
<div id="landlord" style="left:5px;bottom:0px;">
<div class="message" style="opacity:0"></div>
<canvas id="live2d" width="500" height="560" class="live2d"></canvas>
<div class="live_talk_input_body">
<form id="live_talk_input_form">
<div class="live_talk_input_name_body" >
<input type="checkbox" id="load_this" />
<input type="hidden" id="post_id" value="/2019/07/02/encmail.html" />
<label for="load_this">
<span style="font-size: 11px; color: #fff;">&#160;想问这篇文章</span>
</label>
</div>
<div class="live_talk_input_text_body">
<input name="talk" type="text" class="live_talk_talk white_input" id="AIuserText" autocomplete="off" placeholder="要和我聊什么呀?" />
<button type="submit" class="live_talk_send_btn" id="talk_send">发送</button>
</div>
</form>
</div>
<input name="live_talk" id="live_talk" value="1" type="hidden" />
<div class="live_ico_box" style="display:none;">
<div class="live_ico_item type_info" id="showInfoBtn"></div>
<div class="live_ico_item type_talk" id="showTalkBtn"></div>
<div class="live_ico_item type_music" id="musicButton"></div>
<div class="live_ico_item type_youdu" id="youduButton"></div>
<div class="live_ico_item type_quit" id="hideButton"></div>
<input name="live_statu_val" id="live_statu_val" value="0" type="hidden" />
<audio src="" style="display:none;" id="live2d_bgm" data-bgm="0" preload="none"></audio>
<input id="duType" value="douqilai" type="hidden" />
</div>
</div>
<div id="open_live2d">召唤伊斯特瓦尔</div>
<!-- <![endif]-->
<footer>
<p>
<small>Made with ❤ by Mayx<br />Last updated at 2025-12-01 00:00:10<br /> 总字数:613841 - 文章数:177 - <a href="/atom.xml" >Atom</a> - <a href="/README.html" >About</a></small>
</p>
</footer>
</div>
<script src="/assets/js/scale.fix.js"></script>
<!--[if !IE]> -->
<script src="/assets/js/main_new.js"></script>
<script src="/Live2dHistoire/live2d/js/live2d.js"></script>
<script src="/Live2dHistoire/live2d/js/message.js"></script>
<!-- <![endif]-->
</body>
</html>