Hello! I’m trying to create a simple app on Android that allows me to configure my Photon’s WiFi connection. I’m able to get pretty far but I’m stuck on the password encryption. I’ve tried to translate the CLI Node example I’ve seen into Java but with no luck (https://github.com/spark/softap-setup-js/blob/master/softap.js). I know the public key being returned is in PKCS#1 format. So, for example, if I query the Photon using this URL: http://192.168.0.1/public-key, I get the following hex encoded public key:

30819F300D06092A864886F70D010101050003818D003081890281810090F90CE05D6FD39D889850E3E17129F7269A79D3847F9E252F35429BA06DCF7EDF86FB3DA06E30603A32158A25B8719859DB3C72DAED263B85AD36BE70B7FA8B280E26A79A93C34AEEE455074B6A64368D00E0190498A6E9B9E74A643E04690BE52581DA93B1ABF1DFC8AF82D0B07D7599483D10307C82ACB2780090DA26AA3F0203010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

The Node code slices out the first 22 bytes (I’m assuming it’s trying to get to the modulus). Then it passes that into some built-in Node methods to create the RSA public key. I think the exponent in the above string is 0x010001 (65537 decimal). After the exponent there are a ton of zeros (I guess padding for some reason?).

Does anyone have a Java example that can take the hex encoded public key (above) and create an RSAPublicKeySpec. I’d love to see the following Node code translated into Java. Any help is greatly appreciated.

```
SoftAP.prototype.publicKey = function publicKey(cb) {
is(cb);
var sock = this.__sendCommand('public-key', response.bind(this));
function response(err, dat) {
if(err) { return cb(err); }
if(!dat) { return cb(new Error('No data received')); }
if(dat.r !== 0) {
return cb(new Error('Received non-zero response code'));
}
var buff = new Buffer(dat.b, 'hex');
this.__publicKey = new rsa(buff.slice(22), 'pkcs1-public-der', {
encryptionScheme: 'pkcs1'
})
cb(null, this.__publicKey.exportKey('pkcs8-public'));
};
return sock;
};
```