尝试在PHP中使用shell_exec通过openssl创建证书

耶稣·米兰

我实际上是为自己一个小项目,它是一个Web应用程序,可以创建证书签名请求以及证书.pem/.crt及其证书.key

实际的问题是我正在尝试运行:

shell_exec(openssl ca -config ../openssl.cnf -in $CSR_FILE -out $CRT_FILE)

而且我发现了一个问题,运行此命令后要求输入我的CA密码,随后又两次回答“是”以接受证书的创建。我不知道如何使它工作。我已经坚持了将近三天,Google或Stack Overflow都没有答案。

我尝试运行该命令并添加另一个命令,以shell_exec(passphrase)这种方式两次传递密码和“ y”。

shell_exec("openssl....","passphrase","y","y")

非常感谢您,我感谢所有帮助。

普里亚

您不必为此使用shell_exec()您可以使用openssl_csr_new() PHP函数创建自签名证书

它根据dn提供的信息生成一个新的CSR(证书签名请求),该信息代表将在证书中使用的专有名称。

PHP代码以生成自签名证书

<?php 
// For SSL certificates, the  commonName is usually the domain name of
// that will be using the certificate, but for S/MIME certificates,
// the commonName will be the name of the individual who will use the certificate.
$dn = array(
    "countryName" => "UK",
    "stateOrProvinceName" => "Somerset",
    "localityName" => "Glastonbury",
    "organizationName" => "The Brain Room Limited",
    "organizationalUnitName" => "PHP Documentation Team",
    "commonName" => "Wez Furlong",
    "emailAddress" => "[email protected]"
);

// Generate a new private (and public) key pair
$privkey = openssl_pkey_new();

// Generate a certificate signing request
$csr = openssl_csr_new($dn, $privkey);

// You will usually want to create a self-signed certificate at this
// point until your CA fulfills your request.
// This creates a self-signed cert that is valid for 365 days
$sscert = openssl_csr_sign($csr, null, $privkey, 365);

// Now you will want to preserve your private key, CSR and self-signed
// cert so that they can be installed into your web server.

openssl_csr_export($csr, $csrout) and var_dump($csrout);
openssl_x509_export($sscert, $certout) and var_dump($certout);
openssl_pkey_export($privkey, $pkeyout, "mypassword") and var_dump($pkeyout);

// Show any errors that occurred here
while (($e = openssl_error_string()) !== false) {
    echo $e . "\n";
}
//save certificate and privatekey to file
file_put_contents("certificate.cer", $certout);
file_put_contents("privatekey.pem", $pkeyout);
?>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

通过php shell_exec的Docker命令

来自分类Dev

尝试使用 PHP shell_exec() 将 CSV 导入 MongoDB 但似乎不起作用

来自分类Dev

在PHP中使用shell_exec()函数时,没有任何反应

来自分类Dev

如何在 php shell_exec 中使用“dns-sd”命令?

来自分类Dev

php,bash,sshpass,scp无法通过shell_exec工作

来自分类Dev

php-使用shell_exec运行shell命令

来自分类Dev

无法使用PHP shell_exec()执行telnet命令

来自分类Dev

使用shell_exec从PHP内调用Python

来自分类Dev

使用shell_exec php删除计划任务

来自分类Dev

如何使用 PHP shell_exec 编辑 crontab

来自分类Dev

npm安装无法通过php system()运行(exec / shell_exec)

来自分类Dev

动态创建脚本的Shell_exec与else

来自分类Dev

通过PHP中的shell_exec从自定义文件输出shell输出

来自分类Dev

即使在/ etc / sudoers中使用NOPASSWD,PAM仍需要exec / shell_exec的密码

来自分类Dev

设置php和ffmpeg的ENV PATH以在带有CLI的shell脚本中的PHP脚本中使用它,例如shell_exec()

来自分类Dev

PHP从shell_exec删除隐藏的字符

来自分类Dev

Nginx中的PHP shell_exec权限

来自分类Dev

php shell_exec返回null

来自分类Dev

PHP shell_exec System.OutOfMemoryException

来自分类Dev

PHP,而shell_exec Kill -9

来自分类Dev

Nginx中的PHP shell_exec权限

来自分类Dev

PHP shell_exec()-详细输出?

来自分类Dev

从php shell_exec()运行node js

来自分类Dev

PHP shell_exec()SASS-更新

来自分类Dev

结束 shell_exec 进程 PHP

来自分类Dev

通过shell_exec()从PHP调用“ firebase deploy”不起作用

来自分类Dev

使用 shell_exec git pull

来自分类Dev

用PHP shell_exec()循环:使用php for()或bash做完吗?

来自分类Dev

无法通过PHP中的shell_exec()函数运行wkhtmltopdf逗号,但在命令行上可以使用相同的命令

Related 相关文章

  1. 1

    通过php shell_exec的Docker命令

  2. 2

    尝试使用 PHP shell_exec() 将 CSV 导入 MongoDB 但似乎不起作用

  3. 3

    在PHP中使用shell_exec()函数时,没有任何反应

  4. 4

    如何在 php shell_exec 中使用“dns-sd”命令?

  5. 5

    php,bash,sshpass,scp无法通过shell_exec工作

  6. 6

    php-使用shell_exec运行shell命令

  7. 7

    无法使用PHP shell_exec()执行telnet命令

  8. 8

    使用shell_exec从PHP内调用Python

  9. 9

    使用shell_exec php删除计划任务

  10. 10

    如何使用 PHP shell_exec 编辑 crontab

  11. 11

    npm安装无法通过php system()运行(exec / shell_exec)

  12. 12

    动态创建脚本的Shell_exec与else

  13. 13

    通过PHP中的shell_exec从自定义文件输出shell输出

  14. 14

    即使在/ etc / sudoers中使用NOPASSWD,PAM仍需要exec / shell_exec的密码

  15. 15

    设置php和ffmpeg的ENV PATH以在带有CLI的shell脚本中的PHP脚本中使用它,例如shell_exec()

  16. 16

    PHP从shell_exec删除隐藏的字符

  17. 17

    Nginx中的PHP shell_exec权限

  18. 18

    php shell_exec返回null

  19. 19

    PHP shell_exec System.OutOfMemoryException

  20. 20

    PHP,而shell_exec Kill -9

  21. 21

    Nginx中的PHP shell_exec权限

  22. 22

    PHP shell_exec()-详细输出?

  23. 23

    从php shell_exec()运行node js

  24. 24

    PHP shell_exec()SASS-更新

  25. 25

    结束 shell_exec 进程 PHP

  26. 26

    通过shell_exec()从PHP调用“ firebase deploy”不起作用

  27. 27

    使用 shell_exec git pull

  28. 28

    用PHP shell_exec()循环:使用php for()或bash做完吗?

  29. 29

    无法通过PHP中的shell_exec()函数运行wkhtmltopdf逗号,但在命令行上可以使用相同的命令

热门标签

归档