首页
关于
Search
1
网站回归
32 阅读
2
当我指出 ChatGPT 的错误,它竟然改过来了
30 阅读
3
AES 加密通讯教程
26 阅读
4
以色列施行了种族灭绝吗?——数字来说明
25 阅读
5
Mac Os 在终端下复制粘贴字符串的时候,偶然多了一对 00~ 01~ 字符
24 阅读
默认分类
科技
财经
军事
社会
历史
编程
随笔
教育
登录
Search
标签搜索
以色列
苏联
伊朗
巴勒斯坦
ChatGPT
JavaScript
AI
笑话
银行
华侨银行
终端
Mac Os
Linux
外国人
俄罗斯
女孩
滴滴
就业
手机
华为
Bread
累计撰写
21
篇文章
累计收到
0
条评论
首页
栏目
默认分类
科技
财经
军事
社会
历史
编程
随笔
教育
页面
关于
搜索到
4
篇与
的结果
2025-08-12
AES 加密通讯教程
爱丽丝和鲍勃想要通过AES来加密他们的通讯首先他们需要通过安全的方式约定好加密方式。例如他们可以在线下见面,约定好用 AES-GCM 加密,并用一段 32 位的随机密钥当作密码。为什么他们要先下约定好密钥,因为如果他们没有安全的通讯方式,他们的密钥就会被窃听到,例如他们通过微信发送密钥,腾讯后台就看到他们的密钥了,以后他们的通讯都可以用这个密钥解密,他们却不知道。如果他们有现有的线上安全通讯方式,例如通过安全邮箱发送,也是可以的。例如这些安全邮箱:inbox.lv tuta.com protonmail.com 32 位的随机密钥如何获取?如果他们有工具本地生成也可以。或者用线上的服务也可以,例如这个 https://nanojs.net/tool/encode/key-generator ,可以生成一段 base64 格式的 32 位密钥作为两人的密钥。这个网站是没有服务端的,所有代码在浏览器上运行,网站后台无法获取你的密钥。例如两人约定的密钥如下cR8uBj02LnW1zllyV9KkvxDTRFTxz8awXGuyCoQ+ico=现在,两人约定好了使用 AES-GCM 加密,密钥使用上面的 32 位的 base64 编码密钥。他们可以开始安全的通讯了。他们分开后,回到家里,拿起不安全的微信、QQ、网易邮箱等 APP ,开始通讯。爱丽丝想说:hello Bob ,但她不直接发这条信息,她把这条信息用 AES-GCM 配合她与鲍勃约定好的密钥加密。如果她本地能运行加密算法,例如用一些加密软件,或者自己编程,她可以本地加密,如果没有条件也可以用线上的服务,例如:https://nanojs.net/tool/encode/aes-gcm 。这个网站没有后台,加密操作在浏览器上完成,不用担心后台偷看她的内容。加密后得到一段 base64 编码的密文:cXW/hPMvwYhnD8d6E/OdsM4jDbY3w8+PcboKJlatmVmdSg4Uxw==(注意,每次加密会用到随机的 iv ,所以每次加密后的密文都不一样,你可以亲自操作试试,结果肯定和我不一样,但用同一个密钥是可以解开的,你可以尝试一下)爱丽丝把上面的密文发给鲍勃。微信企图监听他们的通讯,但只截取到密文,没有密钥无法破解。鲍勃收到之后用密钥解密,得到明文 hello Bob 。如果鲍勃有办法本地解密,他可以本地解密。如果没有的话就用线上服务吧:https://nanojs.net/tool/encode/aes-gcm同理,鲍勃想要回消息,他也用同样的密钥加密,从此他们实现了安全加密通讯。微信在后台监听了他们大量的谈话,但都是密文无法解密。偷听者可以尝试暴力破解,但 32 位密钥的安全性是在太高了,有 2 的 256 次方种组合,比地球上的原子多多了。哪怕全国的电脑一起破解,到世界末日也破解不出来。还有哪些漏洞呢?虽然通讯方式安全了,但是还有一些漏洞:浏览器,操作系统,输入法,都有可能泄漏你的通讯内容。浏览器要用安全的,例如 chrome firefox brave ,最起码也用 edge ,不要用任何国内浏览器,除了广告多,还不安全。操作系统不要用国内的。输入法可以用安全操作系统自带的,或者 rime 输入法,不要用国内的。要限制 app 读取剪切板内容,限制 app 录制屏幕,使用摄像头和麦克风。密钥建议用随机的,增加安全性。可以用一段 32 字节的字符转为密钥,例如 abcdabcdabcdabcdabcdabcdabcdabcd ,这样好记,但不安全(相对于随机密钥不安全,但也足够安全了)。约定密钥一定要通过安全的方式,不能在不安全的通讯方式上传递,线下最好,能保证没有人监听,且对方收到的是和自己一样的密钥。储存密钥也要注意,如果你发在朋友圈里,或者记在说说里,就泄漏给腾讯后台了。保存在纸上,例如两维码,或者安全的地方,确保没人知道。定期更换密钥可以增加安全性。如果一个礼拜更换一次,一旦泄漏,别人最多监听你们一个礼拜。常见问题多人通讯怎么办?可以多人共享一个密钥,但要确保每个人可靠,没有人是内鬼泄漏密钥。人越多越不安全如果使用 16 位密钥安全吗?16 位相当于 128 比特,2 的 128 次方的组合,也非常安全了,集全国之力也很难破解。非对称加密怎么样?非对称加密使用公钥加密,私钥解密,私钥签名。非对称加密可以公开自己的公钥,可以签名,但私钥泄漏同样不安全,也同样需要解决中间人攻击的问题。非对称加密常用与交换密钥。如果一群人使用私钥加密,大家就需要记住每一个人的公钥,会更复杂,但一个人的私钥泄漏了,不会影响其他人,其他人仍然可以安全通讯。
2025年08月12日
26 阅读
0 评论
0 点赞
2024-12-15
Linux 用户和用户组管理
创建和删除用户组groupadd 和 groupdel 命令可以创建和删除用户组groupadd test groupdel testuseradd 可以创建用户 -g 指定用户组,不指定则创建同名组 -d 指定 home 目录,不指定则为 /home/usernamegroupadd testg mkdir /home/testu useradd testu -g testg -d /home/testuuserdel 可以删除用户-r 同时删除 home 目录userdel testu -rid 命令可以查看用户所属的组id caddy uid=999(caddy) gid=997(caddy) groups=997(caddy)将用户添加到组可以用 usermod -aGgroupadd g1 groupadd g2 useradd u1 -g g1 usermod -aG u1 g2 usermod: group 'u1' does not exist usermod -aG g2 u1 id u1 uid=1000(u1) gid=1001(g1) groups=1001(g1),1002(g2)getent passwd 查看有哪些用户显示:用户名:密码(x代替):用户id:组id:描述信息:home目录:执行终端getent passwd sshd:x:101:65534::/run/sshd:/usr/sbin/nologin caddy:x:999:997:Caddy web server:/var/lib/caddy:/usr/sbin/nologin u1:x:1000:1001::/home/u1:/bin/shgetent group 可以查看组getent group _ssh:x:108: caddy:x:997: g1:x:1001: g2:x:1002:u1添加用户到 sudoerusermod -aG sudo username
2024年12月15日
16 阅读
0 评论
0 点赞
2024-12-14
Mac Os 在终端下复制粘贴字符串的时候,偶然多了一对 00~ 01~ 字符
Mac Os 的终端有一个鲜为人知很少使用的功:是括号粘贴模式(bracketed paste mode)。当您处于括号粘贴模式并粘贴到终端时,内容将由序列 \e[200~ 和 \e[201~ 包裹。例如,假设我从网站复制了字符串 echo 'hello'\n。当我粘贴到终端时,它会向正在运行的任何程序发送 \e[200~echo 'hello'\n\e[201~。这个功能可以让程序可以区分您手动输入的内容和您粘贴的内容。为什么需要这个功能呢?例如,许多终端应用程序专门处理某些字符:特别是当您按下回车键时,它会发送一个换行符。大多数 shell 会在此时执行输入缓冲区的内容。这通常是您想要的,但也可能不是。同时,这意味着如果您粘贴到终端中的任何内容中有换行符,它们也会运行输入缓冲区的内容。有时发现突然终端打开了括号粘贴模式,为什么终端会打开括号粘贴模式呢?其实大部分情况都不是我们主动开启的,是由个别软件在无意中将括号粘贴模式开启的。当开启了括号粘贴模式粘贴的字符串收尾会多了一对字符:00~ xxx 01~,一般情况下我们把括号粘贴模式关闭就可以了。解决方案只需在终端关闭括号粘贴模式即可:printf "\e[?2004l"那如果想主动开启括号粘贴模式该如何操作呢?也只需在终端开启括号粘贴模式即可:printf "\e[?2004h"
2024年12月14日
24 阅读
0 评论
0 点赞
2024-11-30
当我指出 ChatGPT 的错误,它竟然改过来了
ChatGPT 的回答一般挺不错的,比搜索引擎好很多。经常问它一些问题,大部分时候有满意的答案。当然不是 100% 满意,有时答案是错的,甚至明显是错的,然后我就会忽略错误答案,或者它的回答不完全对,但我也能补充出正确答案,然后就结束对话了。但今天我尝试指出它的错误,它竟然修复了。起因:我想写一段 JavaScript 使用 sftp 传文件夹的代码,首先安装依赖npm install ssh2-sftp-clientChatGPT 给的答案是:const Client = require('ssh2-sftp-client'); const path = require('path'); const fs = require('fs'); const sftp = new Client(); const config = { host: 'your.server.com', port: 22, username: 'your-username', password: 'your-password', // Alternatively, use SSH keys // privateKey: require('fs').readFileSync('/path/to/your/private-key') }; const localDir = '/path/to/local/folder'; // Local directory to upload const remoteDir = '/path/to/remote/folder'; // Remote destination directory // Function to recursively upload files and directories async function uploadDir(localPath, remotePath) { try { // Connect to the SFTP server await sftp.connect(config); // Ensure the remote directory exists await sftp.mkdir(remotePath, true); // 'true' means recursive mkdir // Read the contents of the local directory const files = await fs.promises.readdir(localPath); // Iterate through each file/subdirectory in the local directory for (let file of files) { const localFile = path.join(localPath, file); const remoteFile = path.join(remotePath, file); // Check if it's a file or directory const stats = await fs.promises.stat(localFile); if (stats.isDirectory()) { // If it's a directory, recursively upload it await uploadDir(localFile, remoteFile); } else { // If it's a file, upload it await sftp.put(localFile, remoteFile); console.log(`Uploaded file: ${localFile} -> ${remoteFile}`); } } console.log('Directory upload complete!'); } catch (err) { console.error('Error uploading directory:', err); } finally { // Close the SFTP connection sftp.end(); } } // Start uploading the directory uploadDir(localDir, remoteDir);这里有个问题,文件夹可能会有子文件夹,会递归调用 uploadDir 方法,在递归调用时会重复连接 sftp ,会报错:Error: connect: An existing SFTP connection is already defined at SftpClient.fmtError (/Users/wjf/wjf/repo/js-scp/node_modules/ssh2-sftp-client/src/index.js:94:22) at SftpClient.connect (/Users/wjf/wjf/repo/js-scp/node_modules/ssh2-sftp-client/src/index.js:188:20) at uploadDir (/Users/wjf/wjf/repo/js-scp/test2.js:32:20) at uploadDir (/Users/wjf/wjf/repo/js-scp/test2.js:50:23) { code: 'ERR_NOT_CONNECTED', custom: true }于是向 ChatGPT 指出错误:This code do not work. Because in the recursion, you connect sftp multiple times于是 ChatGPT 重新写了代码,把连接 sftp 放在递归函数的外面,给出了可运行的代码。const Client = require('ssh2-sftp-client'); const path = require('path'); const fs = require('fs'); const sftp = new Client(); const config = { host: 'your.server.com', port: 22, username: 'your-username', password: 'your-password', // Alternatively, use SSH keys // privateKey: require('fs').readFileSync('/path/to/your/private-key') }; const localDir = '/path/to/local/folder'; // Local directory to upload const remoteDir = '/path/to/remote/folder'; // Remote destination directory // Function to recursively upload files and directories async function uploadDir(localPath, remotePath) { try { // Read the contents of the local directory const files = await fs.promises.readdir(localPath); // Iterate through each file/subdirectory in the local directory for (let file of files) { const localFile = path.join(localPath, file); const remoteFile = path.join(remotePath, file); // Check if it's a file or directory const stats = await fs.promises.stat(localFile); if (stats.isDirectory()) { // If it's a directory, create it on the remote server await sftp.mkdir(remoteFile, true); // 'true' means recursive mkdir console.log(`Created directory: ${remoteFile}`); // Recursively upload the directory's contents await uploadDir(localFile, remoteFile); } else { // If it's a file, upload it await sftp.put(localFile, remoteFile); console.log(`Uploaded file: ${localFile} -> ${remoteFile}`); } } console.log('Directory upload complete!'); } catch (err) { console.error('Error uploading directory:', err); } } // Start the upload process async function startUpload() { try { // Connect to the SFTP server once await sftp.connect(config); // Upload the entire directory await uploadDir(localDir, remoteDir); } catch (err) { console.error('Error during connection or upload:', err); } finally { // Always end the SFTP connection when done sftp.end(); } } // Start the process startUpload();没想到人工智能还可以这样操作!
2024年11月30日
30 阅读
0 评论
0 点赞