SoftAP setup, Password Encryption Issues, configure-ap error 1040

For starters, I have yet to find any good documentation regarding the Particle Photon’s SoftAP setup – such as the commands like configure-ap, device-id, scan-ap, etc. I’ve only found these commands by disecting the SoftAP.js

I am not using the SoftAP.js as I am using my own code from scratch.

Everything is working fine (public-key, scan-ap, etc), except when sending the configire-ap command, I get a error from the photon, error 1040. Which translates to -0x0410 =TROPICSSL_ERR_RSA_INVALID_PADDING

I am pretty certain the encryption is working as expected, but i am questioning the public-key’s length I am getting from the photon. It’s 588 characters long (hex format), which includes a bunch of padded zeros on the end. Shouldn’t this public-key be 256, 512, 1024, or 2048 long?

If the length is right – any other ideas what could be the issue?

Code:

I am using RSA encryption from this site here: http://www-cs-students.stanford.edu/~tjw/jsbn/

var rsa = new RSAKey();
rsa.setPublic(publicKeyFromPhoton, “10001”);
var result = rsa.encrypt(securePass);

The public key is a HEX representation of a DER-encoded PKCS1.5 key. The code you posted above there looks like you are trying to use the entire key as the exponent. What’s the reason for not using softap.js? Surely this wheel doesn’t need re-inventing? :smile:

I’m creating an app in Apache Cordova.

SoftAp.js is Node based. I tried the browserify option, but still ran in to issues getting it to work on my system.

Also, SoftAp is way overly complex and overkill. It appears the encryption code included with SoftAp includes way more than what is really needed. And the browserify package is over a 1MB in size because of all of the Node baggage.

I’ll check in to the exponent/mod parsing and report back.
Thanks!

That’s what it was. Thanks!

I ended up using JSEncrypt instead, although it required a tweak of it’s encryption function to return it in Hex format instead of Base64.

https://github.com/travist/jsencrypt - nice and lightweight encryption. 55kb minify-ed.

Awesome! Glad you got it resolved! I’ll pass on your comments about softap being bloated to the open-source team! :+1:

I’d gladly share my version once it’s refined. It’s purely jQuery based with the JSEncrypt package. No Node.js needed.

Let me know if that is of interest.

1 Like