I receive a RSA Key from C# server through httprequest,
But so many Encrypt lib need PEM format.
I find a solution at this
But I can't use it in my Javscript H5 Project, Have any other solution?
I receive a RSA Key from C# server through httprequest,
But so many Encrypt lib need PEM format.
I find a solution at this
But I can't use it in my Javscript H5 Project, Have any other solution?
Your XML seems a propietary format
<RSAKeyValue>
<Modulus>1znidPBIcMcO7K/53tkTSyKqxlG5Mcws8kVtijS4tyEU4W/FEVWYpOtv+Stnb4Vt</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
You will need a cryptographic library like forge to build a RSA public key from modulus and exponent. Based on this thread , you can use a code similar to 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 a Forge public key from modulus and exponent
var publicKey = forge.pki.setRsaPublicKey(
parseBigInteger(rsaKeyValue.Modulus), // n
parseBigInteger(rsaKeyValue.Exponent)); // e
// convert a Forge public key to PEM-format
var pem = forge.pki.publicKeyToPem(publicKey);