trying to convert from java x509 key to php and decode string -


anyone can convert code java php ? read more below..

so .. got piece of code .. i'm trying convert php ( 5.{3,4,5} .. doesn't matter .. don't want run tomcat , stuff )

  private static byte[] caglt(string lc){       try {           publickey public_key;           string key = "miibudccaswgbyqgsm44baewggefaogbap1/u4eddriput9knc7s5of2ebdspo9e.............long 593 char stuff here";           keyfactory keyfactory = keyfactory.getinstance("dsa");           public_key = keyfactory.generatepublic(new x509encodedkeyspec(base64.decodebase64(key.getbytes())));           byte[] decodedbytes = base64.decodebase64(lc.getbytes());           bytearrayinputstream in = new bytearrayinputstream(decodedbytes);           datainputstream din = new datainputstream(in);           int textlength = din.readint();           byte[] lt = new byte[textlength];           din.read(lt);           byte[] hash = new byte[din.available()];           din.read(hash);           try{               signature signature = signature.getinstance("sha1withdsa");               signature.initverify(public_key);               signature.update(lt);               try{                   signature.verify(hash);               } catch (exception e) {                     throw e;               }           }catch (exception e){               throw e;           }           return lt;       }catch (exception e){           throw new error(e);       }   } 

as read it, gets public_key x509 , decodes string gets using public_key per x509 spec

i've been trying in php no luck ...

$key = "miibudccaswgbyqgsm44baewggefaogbap1/u4eddriput9knc7s5of2ebdspo9e.............long 593 char stuff here"; $key = "-----begin public key-----\n" . wordwrap($key, 64, "\n", true) . "-----end public key-----"; // no \n before ----end because has 1 $key = openssl_pkey_get_public($key); $key = openssl_pkey_get_details($key); $key = "-----begin public key-----\n" . wordwrap(base64_encode($key['dsa']['pub_key']), 64, "\n", true)."\n-----end public key-----";         $data = null;         openssl_public_decrypt($todecode, $data, $key); 

which yells

php warning: openssl_public_decrypt(): key parameter not valid public key

also tried phpseclib ( http://phpseclib.sourceforge.net/pear.htm )

$key = "miibudccaswgbyqgsm44baewggefaogbap1/u4eddriput9knc7s5of2ebdspo9e.............long 593 char stuff here"; $key = "-----begin public key-----\n" . wordwrap($key, 64, "\n", true) . "-----end public key-----"; $data = null; openssl_public_decrypt($licensecontent, $data, $key); 

which yells

openssl_public_decrypt(): key type not supported in php build!

and this:

include('biginteger.php'); include('asn1.php'); include('x509.php'); $key = "miibudccaswgbyqgsm44baewggefaogbap1/u4eddriput9knc7s5of2ebdspo9e.............long 593 char stuff here"; $key = "-----begin certificate-----\n" . wordwrap($key, 64, "\n", true) . "-----end certificate-----"; $x509 = new file_x509(); $cert = $x509->loadx509($key); print_r($cert); 

which yells nothing... also:

$key = "miibudccaswgbyqgsm44baewggefaogbap1/u4eddriput9knc7s5of2ebdspo9e.............long 593 char stuff here"; $key = "-----begin certificate-----\n" . wordwrap($key, 64, "\n", true) . "-----end certificate-----"; echo openssl_x509_read($key); 

openssl_x509_read(): supplied parameter cannot coerced x509 certificate!

i'm out of ideas...

anyone can convert code java php ?

any ideas .. appreciated. please don't shoot if has been answered ( did google , found info no luck trying apply. in advance.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -