openssl - openssl_sign(): supplied key param cannot be coerced into a private key -


i have googled search answer these problem.but i'm not able find proper solution question many answer specific problem related.

when tried create digital signature of content using xmlsecuritykey , openssl_sign i'm getting warning , signature not created.

openssl_sign throwing error :

warning: openssl_sign(): supplied key param cannot coerced private key in /var/www/git/ta_client/accessservice.php on line 105 

and code is:

public function _signmessage($encdata, $configvalues)     { $decode = 'decode';     $token = $encdata['token'];     $ciphervalue = $encdata['ciphervalue'];     $clientid = $encdata['clientid'];     $grpcustnum = $encdata['grpcustnum'];      // sign concatenated string     $tosign = $token . $ciphervalue . $clientid . $grpcustnum;      // encrypt token public key vendor     $cipher = new xmlsecuritykey(xmlsecuritykey::rsa_sha1, array('type'=>'private')); // reference 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 decode values     $encdata['sign'] = urlencode(base64_encode($signature)) . $decode;     $encdata['token'] = urlencode($token) . $decode;     $encdata['ciphervalue'] = urlencode($ciphervalue) . $decode;      return $encdata; } 

and $configvalues['privkey'] in xml format.any suggestions?

openssl doesn't support xml format. recommendation use phpseclib. ie.

<?php include('crypt/rsa.php');  $rsa = new crypt_rsa(); $rsa->loadkey('...'); // private key  $plaintext = '...';  $rsa->setsignaturemode(crypt_rsa_signature_pkcs1); $signature = $rsa->sign($plaintext); 

i'm assuming private key you're trying load in format?:

<rsakeyvalue>   <modulus>akoyq6q7un7vofmpr4fsq2norxhbmkm8p7h4jnqu+qulrxvyll9cn8obhixq9sncykbzbvbkqn4zymm4vlswy66wwdwlnyfdteo1rj6yzbexiarvvx/ep6yrnps1b7m7t2uc2ypq1dnwzvi+sigr51s1/ronqzswkpjhh71pthln</modulus>   <exponent>aqab</exponent>   <p>an4ddp+ihbca6qejh4xlm3iexzlajxyrjid6vdwmh4t42nar5nem8ax39o3nd9b1zoj41f9zfqmuz8/agabreku=</p>   <q>amqi+r0g9m0k+acqk3dfpv4rd9jgc0tle98henyt7eqvzuuiq4xjvrz0ybqn//boafrkhstprs9dq7eepkli4bs=</q>   <dp>fklyr1uz/wpjjj611cdbcztlpdqoxssqgnh85bzcj/u3wqbpe2vjvyyvyi5kx6zk7s0ljktt2jny2+00vsberq==</dp>   <dq>ajgc1mg5oydo5nwd6birorpxgo2bptbu/fhrt8ebhktz2eplu9vqqsqzy1ozmvx8i1m5wutlpz2yljibqvdxqhm=</dq>   <inverseq>eaik5khknp9sfxulvwqalvzyhk0fhnnzcznfuwnlcxb6wnkg117fefy91ehntt5pzyppf+xzd1fnp7/qsininq==</inverseq>   <d>fijko56+qgyn8m0rvyaraxz++xtqhblh3tx4vgmtrq+wegcjhotwo23kmbaujgsynrmobzm3lmftkevikaidpexvycdm5dyq3xtolkklv5l2piivofmdg+kesnafv7l2c+cnzrmw0+b6f8mr1cjzzuxvll6q02fvli55/mbsyxe=</d> </rsakeyvalue> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -