0

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.

Jose Rodriguez
  • 9,753
  • 13
  • 36
  • 52
smnnekho
  • 21
  • 3
  • node.js uses different code under water I'm afraid – online Thomas Oct 27 '15 at 14:58
  • maybe this (java/android) code is more of a help: https://github.com/spark/spark-setup-android/blob/be2b3c6aab94e8dc596da55704374bc9eedc7afc/devicesetup/src/main/java/io/particle/android/sdk/utils/Crypto.java – smnnekho Oct 27 '15 at 15:14
  • That key is appears to be a SubjectPublicKeyInfo ( [see RFC 5280](http://tools.ietf.org/html/rfc5280) ), except for all the trailing zero bytes. In Java this format is the basis for the X509EncodedKeySpec class. See http://stackoverflow.com/questions/9283716/c-sharp-net-crypto-using-base64-encoded-public-key-to-verify-rsa-signature/9290086#9290086 for a similar question. – President James K. Polk Oct 27 '15 at 21:50
  • thank you for the comments. i figured it out. the answer is here: [link](http://community.particle.io/t/wifisetup-with-c-need-help-with-encryption/16897/9) – smnnekho Oct 28 '15 at 12:58

0 Answers0