javascript - How can I convert RSA PlblicKey XML to PEM format -


i receive rsa key c# server through httprequest,

many encrypt lib need pem format.

find solution @ this

xml pem in node.js

can't use in javscript h5 project, have other solution?

your xml seems propietary format

<rsakeyvalue>      <modulus>1znidpbicmco7k/53tktsykqxlg5mcws8kvtijs4tyeu4w/fevwypotv+stnb4vt</modulus>     <exponent>aqab</exponent> </rsakeyvalue> 

you need cryptographic library forge build rsa public key modulus , exponent. based on thread , can use code similar this

// parse xml var rsakeyvalue = ...  var biginteger = forge.jsbn.biginteger; function parsebiginteger(b64) {      return new biginteger(forge.util.createbuffer(forge.util.decode64(b64)).tohex(), 16);  }   //create forge public key modulus , exponent  var publickey = forge.pki.setrsapublickey(        parsebiginteger(rsakeyvalue.modulus), // n        parsebiginteger(rsakeyvalue.exponent)); // e   // convert forge public key pem-format  var pem = forge.pki.publickeytopem(publickey); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -