为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 PHP 和 OpenSSL 生成自签名证书

如何使用 PHP 和 OpenSSL 生成自签名证书

PHP
繁花如伊 2021-10-08 21:23:06
我正在尝试创建一个使用 PHP 和 openSSL 生成自签名证书的站点。我很确定这是某种语法错误,但我似乎找不到它。我已经在 linux 终端中尝试了该命令,它似乎有效,但仅在 PHP 文件中无效。这是work.php,主要是功能:<?phpfunction terminal($command){        //system        if(function_exists('system'))        {                ob_start();                system($command , $return_var);                $output = ob_get_contents();                ob_end_clean();        }        //passthru        else if(function_exists('passthru'))        {                ob_start();                passthru($command , $return_var);                $output = ob_get_contents();                ob_end_clean();        }        //exec        else if(function_exists('exec'))        {                exec($command , $output , $return_var);                $output = implode(n , $output);        }        //shell_exec        else if(function_exists('shell_exec'))        {                $output = shell_exec($command) ;        }        else        {                $output = 'Command execution not possible on this system';                $return_var = 1;        }        return array('output' => $output , 'status' => $return_var);}?>这是 index.php 这是主文件<form method="post"><input type="text" placeholder="domain" name="name"></input><input type="submit" value="submit" name="submit"></input></form><?phpif(isset($_POST['submit'])){   $name = $_POST["name"];   run();}function run() {require "work.php";$status = 0;$name = $_POST["name"];$command1 = "openssl req -x509 -newkey rsa:4096 -nodes -keyout " . $name . ".key -out " . $name . ".pem -days 3650 -subj '/CN=" . $name . "'";$o = terminal($command1);echo $o['output'];echo "<br><br>";echo "Your certificate >> <a href='" . $name . ".pem'>DOWNLOAD</a>";echo "<br>";echo "Your private key >> <a href='" . $name . ".key'>DOWNLOAD</a>";}?>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 179 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信