在使用PHP OpenSSL扩展库生成证书或密钥时,可以通过以下函数来设置过期时间: openssl_csr_new():生成一个新的证书签名请求(CSR),可以通过设置"config"参数中的"req_extensions"来定义证书的有效期限。 openssl_csr_sign():使用给定的CSR生成一个自签名的证书,可以通过设置"configargs"参数中的"
9、openssl_pkey_import() 从字符串导入私钥或公钥资源 用法:openssl_pkey_import($key, $out, $passphrase=null) 参数: $key:私钥或公钥字符串 $out:输出资源 $passphrase:私钥保护密码(可选) 10、openssl_csr_new() 创建新的证书签名请求(CSR) 用法:openssl_csr_new($info, $privateKey, $configArr) ...
$csr = openssl_csr_new($csrConfig, $privateKey); openssl_csr_export($csr, $csrString); 将CSR保存到文件中。你可以使用以下PHP代码将CSR保存到一个文件中: 代码语言:txt 复制 $csrFile = '/path/to/csr.csr'; file_put_contents($csrFile, $csrString); 使用私钥和CSR生成自签名证书。你可以使...
$decrypted,$priKey);4142echo'公钥加密:',base64_encode($encrypted),'私钥解密:','',$decrypted,'';43echo'---公私钥加解密-END---','';4445//生成文件46$csr= openssl_csr_new($dn,$priKey,$config);//基于$dn生成新的 CSR (证书签名请求)47$sscert= openssl_csr...
PHP的OpenSSL加密扩展学习(三):证书操作 生成CSR 证书签名请求 CSR 是用于生成证书的签名请求,在 CSR 中,我们需要一些 dn 信息。其实也就是当前这个证书的服务对象,包含公司名、邮箱之类的内容。 $privkey = openssl_pkey_new([ "private_key_bits" => 2048,...
openssl扩展提供了很多的函数,这里介绍一下常用的函数: 对称加密函数: 加密:string openssl_encrypt ( string $data , string $method , string $password) 其中data为其要加密的数据,data为其要加密的数据,data为其要加密的数据,method是加密要使用的方法,password是要使用的密匙,函数返回加密后的数据,password是...
$csr = openssl_csr_new($dn, $privateKey); // 将证书签名请求写入文件 openssl_csr_export_to_file($csr, “csr.csr”); “` 4. 自签名证书 使用以下代码可以生成一个自签名证书: “`php $csr = file_get_contents(“csr.csr”); $ca = null; // 自签名证书没有颁发机构 ...
使用OpenSSL扩展可以创建自签名证书,也可以使用已有的证书进行操作。要创建自签名证书,可以使用`openssl_pkey_new`函数生成一个新的密钥对。然后可以使用`openssl_csr_new`函数创建一个证书签名请求(CSR)。最后,使用`openssl_csr_sign`函数对CSR进行签名以生成证书。
$csr = openssl_csr_new($dn, $privkey); $sscert = openssl_csr_sign($csr, null, $privkey, $numberofdays); openssl_x509_export($sscert, $csrkey); //导出证书$csrkey openssl_pkcs12_export($sscert, $privatekey, $privkey, $privkeypass); //导出密钥$privatekey ...
"private_key_type" => OPENSSL_KEYTYPE_RSA, "encrypt_key" => false ); } $csr = openssl_csr_new($dn, $privkey); $sscert = openssl_csr_sign($csr, null, $privkey, 365); echo " CSR: "; openssl_csr_export($csr, $csrout); ...