Does OpenSSL really need a path to openssl.conf?

后端 未结 3 2063
一整个雨季
一整个雨季 2021-02-07 10:47

I want to create a self-signed-certificate in PHP 5.x. with my own (alternative) openssl configuration which should be defined by my PHP code. The PHP script will run on differe

3条回答
  •  [愿得一人]
    2021-02-07 11:33

    Creating a self-signed cert in PHP without OpenSSL (requires phpseclib, a pure PHP X.509 implementation)...

    createKey());
    $privKey->loadKey($privatekey);
    
    $pubKey = new Crypt_RSA();
    $pubKey->loadKey($publickey);
    $pubKey->setPublicKey();
    
    $subject = new File_X509();
    $subject->setPublicKey($pubKey);
    $subject->setDNProp('id-at-organizationName', 'phpseclib demo cert');
    $subject->setDomain('www.whatever.com');
    
    $issuer = new File_X509();
    $issuer->setPrivateKey($privKey);
    $issuer->setDN($subject->getDN());
    
    $x509 = new File_X509();
    $x509->setStartDate('-1 month');
    $x509->setEndDate('+1 year');
    $x509->setSerialNumber(chr(30));
    
    $result = $x509->sign($issuer, $subject);
    echo "the stunnel.pem contents are as follows:\r\n\r\n";
    echo $privKey->getPrivateKey();
    echo "\r\n";
    echo $x509->saveX509($result);
    echo "\r\n";
    

提交回复
热议问题