深入了解 Linux 安全加密技术
1. 非对称密钥加密与解密
非对称密钥加密使用一对密钥,即公钥和私钥。公钥用于加密文件,私钥用于解密文件。以下是使用非对称密钥进行文件加密和解密的步骤:
1. 生成密钥对和密钥环。
2. 将公钥导出到文件。
3. 共享公钥文件。
4. 想要向你发送加密文件的人将你的公钥添加到他们的密钥环中。
5. 使用你的公钥加密文件。
6. 将加密文件发送给你。
7. 使用你的私钥解密文件。
示例代码
$ ls MessageForJohn
MessageForJohn
$ gpg2 --out JillsMessage --decrypt MessageForJohn
<A pop-up window prompts you for a passphrase>
gpg: encrypted with 2048-bit RSA key, ID D9EBC5F7317D3830, created
2019-10-27
"John Doe <jdoe@example.com>"
$ cat JillsMessage
I know you are not the real John Doe.
流程图
graph LR
A[生成密钥对和密钥环] --> B[导出公钥到文件]
B --> C[共享公钥文件]
C --> D[他人添加公钥