在PHP中使用PGP加密文件? [英] Encrypt files using PGP in PHP?

查看:345
本文介绍了在PHP中使用PGP加密文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PGP加密来加密CSV文件,我正在通过PHP脚本生成文件,然后通过电子邮件将该文件发送给客户端.客户端会给我加密密钥,我需要用它来加密文件.

I want to use PGP encryption to encrypt a CSV files, I am generating through a PHP script and then send that file to client via email. Client will give me the encryption key, which I need to use for encryption files.

我在Google上搜索了有关PGP的内容,并发现它是很好的隐私",我也找到了OpenPGP http://www.openpgp.org /和GnuPG http://www.gnupg.org/这两种PGP类型是什么? ?以及我应该使用哪一个?

I Googled about PGP and found it is Pretty Good Privacy, also I found OpenPGP http://www.openpgp.org/ and GnuPG http://www.gnupg.org/ What are these two types of PGP? and which one should I use?

还如何使用客户端提供的密钥在PHP中使用PGP加密文件?

Also how to encrypt a files using PGP in PHP with the key that my client will provide?

我第一次听说过这个词,请问有人可以帮助您理解和使用PHP来实现.

I have heard this term first time, can anyone please help in understanding this and implementing this in PHP.

推荐答案

问题1:关于PGP

  • PGP (很好的隐私)是Symantec Corporation(几年前购买的)的产品和商标.
  • OpenPGP 是PGP使用的标准.
  • GnuPG (Gnu隐私卫士)是PGP的免费开源实现.
  • Question 1: About PGP

    • PGP (Pretty Good Privacy) is a product and trademark of Symantec Corporation (they bought it some years ago).
    • OpenPGP is the standard used by PGP.
    • GnuPG (Gnu Privacy Guard) is a free and open source implementation of PGP.
    • 因此,您要做的是加密为 OpenPGP 密钥.您的客户端使用哪种OpenPGP实施来解密数据对您而言并不重要.在PHP中,通常使用GnuPG,并且内置了接口.

      So what you want to do is encrypt to an OpenPGP key. Which implementation of OpenPGP your client uses to decrypt the data is not important for you. With PHP, commonly GnuPG is used and there are interfaces built-in.

      使用 GnuPG界面,该扩展可以安装用于PHP.

      Use the GnuPG interface, which is an extension that can be installed for PHP.

      首先,导入密钥,其中$keydata是ASCII铠装公共密钥:

      At first, import the key, where $keydata is the ASCII armored public key:

      <?php
      $gpg = new gnupg();
      $info = $gpg -> import($keydata);
      print_r($info);
      ?>
      

      然后使用此密钥加密数据,这次使用客户端密钥的指纹:

      Then use this key to encrypt the data, this time using the client's key's fingerprint:

      <?php
        $gpg = new gnupg();
        $gpg -> addencryptkey("8660281B6051D071D94B5B230549F9DC851566DC");
        $enc = $gpg -> encrypt("just a test");
        echo $enc;
      ?>
      

      如果要加密文件,请阅读并将其传递给encrypt().引用密钥时,请确保至少使用较长的密钥ID(例如DEADBEEFDEADBEEF)和更好的指纹(如示例中所示);和从不使用短键ID(DEADBEEF),因为它们容易受到碰撞攻击.

      If you want to encrypt files, read and pass them to encrypt(). Be sure to use at least long key IDs (eg. DEADBEEFDEADBEEF), better fingerprints (as in the example) when referencing keys; and never use short key IDs (DEADBEEF), as those are vulnerable to collision attacks.

      这是一个更同时做这两种情况的综合示例由用户在PHP手册中添加.

      The is a more comprehensive example for doing both added by a user in the PHP manual.

      这篇关于在PHP中使用PGP加密文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆