我需要PHP等效的以下c#代码:
CLIENT_CERTIFICATE = new X509Certificate2("cert.p12", "passphrase", X509KeyStorageFlags.Exportable);
var stringOfCertWithPrivateKey = Convert.ToBase64String(CLIENT_CERTIFICATE.Export(X509ContentType.Pkcs12));
基本上我需要包含私钥的P12文件的Base64字符串。
目前我尝试了以下代码,但它只给了我公钥:
$cert = 'cert.p12';
$passphrase = 'passphrase';
$certinfo = pathinfo($cert);
$cert = file_get_contents($cert);
// for PKCS12 files
openssl_pkcs12_read($cert, $certs, empty($passphrase) ? '' :$passphrase);
$pkeyid = openssl_pkey_get_private($certs['pkey']);
$pubcert = explode("\n", $certs['cert']);
array_shift($pubcert);
while (!trim(array_pop($pubcert))) {
}
array_walk($pubcert, 'trim');
$pubcert = implode('', $pubcert);
unset($certs);
$this->info($pkeyid);
$this->info($pubcert);
响应:
Resource id #378
MIIFAzCCA+.....N+0zuETh2yYpbTBbPHbPbd
非常感谢任何帮助。