所以我第一次使用加密和解密,遇到了一些问题。要获取我的私钥和公钥,我有以下代码:
//get public key
$client_cert = openssl_x509_read(file_get_contents("path\to\certificate"));
$pub_key = openssl_pkey_get_public($client_cert);
//get private key
$pk = file_get_contents("path\to\pk.pem");
$private_key = openssl_pkey_get_private($pk);
如果我在$ pub_key或$ private_key上运行var转储,我发现它们都是OpenSSL类型的资源。但是,如果我尝试在其中任何一个上运行openssl_pkey_get_details,网页就会死机,我收到一条消息,说网页不可用。如果我尝试运行此行,也会发生这种情况:
openssl_private_encrypt($server_challenge, $encrypted_server_challenge, $private_key);
我已经检查了apache和php日志,但它们都没有显示任何内容。任何帮助将不胜感激
编辑:这是完整的代码块
//get public key
$client_cert = openssl_x509_read(file_get_contents("C:\Users\Brandon\Desktop\Work\ClientCertification.cer"));
$pub_key = openssl_pkey_get_public($client_cert);
//get private key
$pk = file_get_contents("C:\Users\Brandon\Desktop\Work\pk.pem");
$private_key = openssl_pkey_get_private($pk);
$client = new SoapClient("https://ws5.responsys.net/webservices/wsdl/ResponsysWS_Level1.wsdl");
$response = $client->authenticateServer($this->loginParameters);
//encrypt server challenge with private key
$server_challenge = implode($response->result->serverChallenge);
openssl_private_encrypt($server_challenge, $encrypted_server_challenge, $private_key);