我已經搜索到了這些問題的答案。但是我無法找到適合我的問題的解決方案,因爲許多答案都是針對相關問題的。openssl_sign():提供的密鑰參數不能被強制轉換成私鑰
當我試圖創建內容的數字簽名使用XMLSecurityKey
和openssl_sign
我收到警告和簽名沒有創建。
openssl_sign拋出錯誤爲:
Warning: openssl_sign(): supplied key param cannot be coerced into a private key in /var/www/git/ta_client/accessService.php on line 105
而且我的代碼是:
public function _signMessage($encData, $configValues)
{
$decode = 'decode';
$token = $encData['token'];
$cipherValue = $encData['cipherValue'];
$clientId = $encData['ClientId'];
$grpCustNum = $encData['grpCustNum'];
// Sign the concatenated string
$toSign = $token . $cipherValue . $clientId . $grpCustNum;
// Encrypt the token with the public key from vendor
$cipher = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private')); // Reference to XMLSecLibs
$cipher->loadKey($configValues['privkey'], true);
try{
if (! openssl_sign ($toSign, $signature, $cipher->key, OPENSSL_ALGO_MD5)) {
openssl_error_string();
throw new Exception();
}
}catch(Exception $e){
print_r($e);
die;
}
// append the decode values
$encData['sign'] = urlencode(base64_encode($signature)) . $decode;
$encData['token'] = urlencode($token) . $decode;
$encData['cipherValue'] = urlencode($cipherValue) . $decode;
return $encData;
}
而且我$configValues['privkey']
是XML format.Any建議?
ya.My私鑰具有相同的格式。感謝您的回覆。 – stefun