Home > Backend Development > PHP Problem > How to encrypt files using gpg via php

How to encrypt files using gpg via php

醉折花枝作酒筹
Release: 2023-03-11 09:44:02
forward
2714 people have browsed it

Encryption A simple yet practical task is to send encrypted email. For years, the standard for encrypting email has been PGP. But it is commercial software and cannot be used freely. As an alternative to PGP, an open source similar product is now available. GPG does not contain patented algorithms and can be used for commercial applications without restrictions.

How to encrypt files using gpg via php

#Background: The customer provides the private key and requires us to transfer the encrypted file to them through php.

Environment

  • macOS Sierra 10.12.1

  • php 7.0.8

Install gpg environment

macOS:
$ brew install gpg
Copy after login
CentOS
$ yum install gnupg
Copy after login
php

Install gnupg extension, please refer to my old article for specific methods: Use phpize to install the php extension

Import the private key, and the public key will be imported accordingly

$ gpg --import /Users/xjnotxj/downloads/6e.pri
Copy after login

How to encrypt files using gpg via php

Test the correctness of the key[can be skipped]

Encrypted file
$ gpg --recipient 0D39xxxx --output test_file.xls.gpg --encrypt test_file.xls
Copy after login

0D39xxxx => #1

Decrypted file in the above picture
$ gpg -o test_file_new.xls  -d test_file.xls.gpg
Copy after login

Export public key

$ gpg -o pubkey.txt -a --export e6e6xxxx
Copy after login

e6e6xxxx => #

The above is the detailed content of How to encrypt files using gpg via php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template