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 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?
  • ¥15 C#连接不上服务器,
  • ¥20 需要帮我远程操控一下,运行一下我的那个代码,我觉得我无能为力了
  • ¥20 有偿:在ubuntu上安装arduino以及其常用库文件。
  • ¥15 请问用arcgis处理一些数据和图形,通常里面有一个根据点划泰森多边形的命令,直接划的弊端是只能执行一个完整的边界,但是我们有时候会用到需要在有很多边界内利用点来执行划泰森多边形的命令
  • ¥30 在wave2foam中执行setWaveField时遇到了如下的浮点异常问题,请问该如何解决呢?
  • ¥750 关于一道数论方面的问题,求解答!(关键词-数学方法)
  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊