I'm trying to configure wifi credentials for a particle photon (wifi microcontroller with cloud support).
There are existing methods for Java / ios / android / javascript.
However, i need to do this in C# (for a desktop and xamarin multiplatform app).
I succesfully managed to connect to the device, retreive it's ID, retreive the public key and the nearby wifi access points (using Webrequests and deserialized json objects)
However, i am stuck with the RSA encryption of the wifi password i need to pass through.
I'm trying to use the RSACryptoServiceProvider but to encrypt i need to pass a xml string and probably the key in a different (base64?) format. Also there seems to be some kind of splicing that needs to happen.
This is the retreived public key (in HEX):
30819F300D06092A864886F70D010101050003818D00308189028181009885DC94E34A23A2942BB9EB6721C4233E9EDCC9A967F587CEA527E1D447F48319CA6C4178DFF739C0AB079E02467DD4D3AD3214416F0983C3967EA71378D7D93A885F1575D71D009990BFFC0882FC721F4DC98A0D80B4CCF12E51066D69055E9A3C95E247BEB9DC16176A083DE7FA93C23449A3870D599DA9D507964F7FC4B90203010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
This is a function in github softap-js:
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;
};
Which appears to handle the public key. i guess i just need to somehow convert this to .net but i would appreciate any help or hint with that since I'm not familiar at all with encryption.