代码之家  ›  专栏  ›  技术社区  ›  Prix Winteroo

php openssl是否与perl等效?

  •  1
  • Prix Winteroo  · 技术社区  · 16 年前

    以下代码的Perl中创建自签名证书的等效示例是什么?

    我所拥有的一切都是crypt::openssl::rsa(如果有其他模块,请告诉我,以便我可以验证它是否可用或是否可以安装,因为我不是管理员/所有者,并且由于权限问题无法自行安装),我在文档中没有找到有关如何实现这类模块的信息…我确实希望尽可能避免使用命令行命令,但如果这是创建此命令的最后一个方法,就不要使用命令行命令…

    <?php
    // The certificate password
    $passphrase = "some random password";
    
    // Fill in data for the distinguished name to be used in the cert
    // You must change the values of these keys to match your name and
    // company, or more precisely, the name and company of the person/site
    // that you are generating the certificate for.
    // 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.
    $certificateInfo = array(
        "countryName" => "UK",
        "stateOrProvinceName" => "England",
        "localityName" => "London",
        "organizationName" => "blabla",
        "organizationalUnitName" => "Bla bla Developer's Team",
        "commonName" => "blabla.com",
        "emailAddress" => "support@blabla.com"
    );
    
    $configargs = array(
        'digest_alg' => 'sha1',
        'private_key_bits' => 1024,
        'private_key_type' => OPENSSL_KEYTYPE_RSA,
        'encrypt_key' => true
        );
    
    // Generate a new private (and public) key pair
    $privkey = null;
    
    // Generate a certificate signing request
    $csr = openssl_csr_new($certificateInfo, $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, $configargs);//, $configArgs
    
    // Now you will want to preserve your private key, CSR and self-signed
    // cert so that they can be installed into your web server, mail server
    // or mail client (depending on the intended use of the certificate).
    // This example shows how to get those things into variables, but you
    // can also store them directly into files.
    // Typically, you will send the CSR on to your CA who will then issue
    // you with the "real" certificate.
    openssl_csr_export($csr, $csrout);
    openssl_x509_export($sscert, $certout);
    openssl_pkey_export($privkey, $pkeyout, $passphrase);
    ?>
    
    3 回复  |  直到 12 年前
        1
  •  0
  •   ewall    16 年前

    大多数Perl模块,包括您发现的公共crypt::openssl::rsa模块,都只是 openssl 命令。

    所以,我建议您首先考虑一下您需要的数据以及如何在命令行上完成这些工作。有一些很棒的 examples 和 tutorials .

    然后,如果您想从Perl中执行此操作,可以调整 example code from Crypt::OpenSSL::RSA 或来自 OpenCA::OpenSSL (another popular module for integrating OpenSSL commands) 包括所需的值和设置。

    另外,还有一个名为perl的脚本 CA.pl 这包括在每个OpenSSL安装中:这也是一个很好的地方,可以用它们来做例子,并根据您的需要进行调整。(在我的基于Debian的服务器上,它安装在 /usr/lib/ssl/misc/CA.pl ,但可能会有所不同。)

    祝你好运!

        2
  •  0
  •   Bruno    16 年前

    你可以试试 Crypt::OpenSSL::CA , the initial example 似乎做了多少你想要的。您可能需要首先通过其他方法生成密钥对,可能是通过crypt::openssl::rsa。

        3
  •  0
  •   sid_com    12 年前

    试一试 OpenCA::OpenSSL . 我想这应该能满足你的需要。