安装gpg环境 macOS: 解密文件 使用php加密文件 // 设置gnupg在你本机的路径
putenv('GNUPGHOME=/root/.gnupg');
try {
//获取公钥
$publicKey = file_get_contents('application/report/pubkey.txt');
//初始化gpg
$gpg = new gnupg();
//开启调试
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
//导入公钥
$info = $gpg->import($publicKey);
//获取公钥指纹
$gpg->addencryptkey($info['fingerprint']);
//获取需要加密的文件
$uploadFileContent = file_get_contents($filename);
//加密文件
$enc = $gpg->encrypt($uploadFileContent);
//保存文件到本地
$filename = 'application/report/'.'file_xls' . '.gpg';
file_put_contents($filename, $enc);
} catch (Exception $e) {
//log something
return $e->getMessage();
}
// 设置gnupg在你本机的路径 putenv('GNUPGHOME=/root/.gnupg'); try { //获取公钥 $publicKey = file_get_contents('application/report/pubkey.txt'); //初始化gpg $gpg = new gnupg(); //开启调试 $gpg->seterrormode(gnupg::ERROR_EXCEPTION); //导入公钥 $info = $gpg->import($publicKey); //获取公钥指纹 $gpg->addencryptkey($info['fingerprint']); //获取需要加密的文件 $uploadFileContent = file_get_contents($filename); //加密文件 $enc = $gpg->encrypt($uploadFileContent); //保存文件到本地 $filename = 'application/report/'.'file_xls' . '.gpg'; file_put_contents($filename, $enc); } catch (Exception $e) { //log something return $e->getMessage(); }
推荐学习:php视频教程
以上就是如何通过php使用gpg加密文件的详细内容!
查看更多关于如何通过php使用gpg加密文件的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did38052