duanpo2813 2014-10-13 18:35
浏览 60
已采纳

OpenSSL req不适用于PHP Shell

I've been searching for the solution of my problem which is about OpenSSL. I'm using shell_exec() to run shell promts. For example:

shell_exec("openssl genrsa -out myprvkey.pem 1024"); works fine, and generates myprvkey.pem.

However,

shell_exec("openssl req -new -key myprvkey.pem -x509 -days 365 -out mypubcert.pem"); isn't working without giving any errors.

Am I doing something wrong? Thanks. PS: Please remind me if I'm missing something.

OpenSSL Version: 268439647

  • 写回答

1条回答 默认 最新

  • douxuan4556 2014-10-14 13:23
    关注

    Looks like you're trying to create a CSR? If so you can do so using phpseclib, a pure PHP CSR implementation, pretty easily. Here's an example that creates a new RSA key and a new CSR:

    <?php
    include('File/X509.php');
    include('Crypt/RSA.php');
    
    $privKey = new Crypt_RSA();
    extract($privKey->createKey());
    $privKey->loadKey($privatekey);
    
    $x509 = new File_X509();
    $x509->setPrivateKey($privKey);
    $x509->setDNProp('id-at-organizationName', 'phpseclib demo cert');
    
    $csr = $x509->signCSR();
    
    echo $x509->saveCSR($csr);
    ?>
    

    Here's an example that creates a new CSR utilizing an existing RSA key:

    <?php
    include('File/X509.php');
    include('Crypt/RSA.php');
    
    $privKey = new Crypt_RSA();
    $privKey->loadKey('...');
    
    $x509 = new File_X509();
    $x509->setPrivateKey($privKey);
    $x509->setDNProp('id-at-organizationName', 'phpseclib demo cert');
    
    $csr = $x509->signCSR();
    
    echo $x509->saveCSR($csr);
    ?>
    

    (the only diff is that loadKey is being passed a string [which could be populated via file_get_contents or just directly inputted] instead of the output of extract($rsa->createKey()))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 韩国网站购物,KG支付的支付回调如何解决
  • ¥15 workstation导入ovf文件,报错,怎么解决呢?
  • ¥15 关于#c语言#的问题:构成555单稳态触发器,采用LED指示灯延时时间,对延时时间进行测量并显示(如楼道声控延时灯)需要Proteus仿真图和C语言代码
  • ¥50 神舟笔记本,没有linux的驱动,装的Ubuntu系统,想把风扇速度调到最大
  • ¥15 workstation加载centos进入emergency模式,查看日志报警如图,怎样解决呢?
  • ¥50 如何用单纯形法寻优不能精准找不到给定的参数,并联机构误差识别,给定误差有7个?matlab
  • ¥15 workstation加载centos进入emergency模式,查看日志报警如图,没有XFS,怎样解决呢?
  • ¥15 应用商店如何检测在架应用内容是否违规?
  • ¥15 Ubuntu系统配置PX4
  • ¥50 nw.js调用activex