gnupg 和gnupg2_使用GnuPG保守秘密

本文介绍了如何使用GnuPG(GNU Privacy Guard)在PHP中进行加密和解密,包括生成密钥对、导出和导入密钥、加密和解密消息。GnuPG提供了一种在传输和存储数据时确保安全性的方法,适用于需要高度数据安全性的应用。
摘要由CSDN通过智能技术生成

gnupg 和gnupg2

GnuPG stands for GNU Privacy Guard, a form of public key cryptography based on the OpenPGP standard. This article will show you how to perform a few essential tasks with GnuPG using PHP and the GnuPG PECL extension.

GnuPG代表GNU Privacy Guard ,这是一种基于OpenPGP标准的公共密钥加密形式。 本文将向您展示如何使用PHP和GnuPG PECL扩展对GnuPG执行一些基本任务。

For our purposes, as someone who would like to transmit and receive encrypted messages, you need three keys: your own public key, your own private key, and the public key of the person that you would like to communicate with.

就我们的目的而言,作为一个想要发送和接收加密消息的人,您需要三个密钥:您自己的公共密钥,您自己的私有密钥以及您想要与之通信的人的公共密钥。

Private keys should never be shared, but your own is required to generate an encrypted message. Public keys can and must be distributed. Your public key is required by anyone who wishes to encrypt a message intended for your eyes only or to decrypt a message that you have sent them. The public key cannot be used to forge a signature or decrypt messages meant only for you.

私钥绝对不应共享,但需要您自己的私钥才能生成加密的消息。 可以并且必须分配公共密钥。 任何希望加密仅用于您的眼睛的消息或解密已发送给您的消息的人都需要您的公共密钥。 公用密钥不能用于伪造签名或解密仅适合您的消息。

GnuPG also serves as a means to verify the authenticity of non-encrypted data via encrypted signatures, but that topic is not covered here.

GnuPG还用作通过加密签名来验证非加密数据的真实性的方法,但是此处不涉及该主题。

The GnuPG extension discussed here depends on the GnuPG installation on whatever machine you are working with along with the configuration of the user account under which the code will run. The examples provided here are intended to be run from the command line and will interact with the GnuPG environment of the user running them. It should be trivial to extend the concepts here to work from a web script.

此处讨论的GnuPG扩展取决于您正在使用的任何计算机上的GnuPG安装以及将在其下运行代码的用户帐户的配置。 此处提供的示例旨在从命令行运行,并将与运行它们的用户的GnuPG环境进行交互。 扩展此处的概念以通过Web脚本工作应该是微不足道的。

产生金钥 (Generating Keys)

Before you can do anything with GnuPG, you must have a private/public key pair. Though the PECL extension does not let you create these keys right from PHP, you can easily do this from the command line with the gpg command, or a friendly GUI frontend for whatever OS you choose. In Linux, all you need is:

在使用GnuPG进行任何操作之前,必须具有私钥/公钥对。 尽管PECL扩展不允许您直接从PHP创建这些键,但是您可以使用gpg命令或友好的GUI前端从命令行轻松地执行此操作,无论您选择哪种操作系统。 在Linux中,您需要做的是:

gpg --gen-key

After answering a few easy questions about your identity, selecting a passphrase for use of your private key, and accepting the defaults for everything else, your GnuPG keyring will be generated. The keyring stores your keys and the keys of anyone that you plan to interact with.

在回答了一些有关您的身份的简单问题,选择了使用私钥的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值