【发布时间】:2014-03-24 12:09:42
【问题描述】:
我已经用谷歌搜索这些问题的答案。但我无法为我的问题找到合适的解决方案,因为许多答案都是针对问题相关的。
当我尝试使用 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 格式。有什么建议吗?
【问题讨论】:
标签: openssl rsa digital-signature php-openssl