SoftAP Java Example Help

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 ( I know the public key being returned is in PKCS#1 format. So, for example, if I query the Photon using this URL:, I get the following hex encoded public key:


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) {
	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;

Hi @jdarden

I am sorry that I cannot answer your Java question directly but I can tell you a bit about the key format you have there. It is easy to check the output by putting the binary data into a file and then base64 encoding that and add the beginning and ending headers like this:

-----END PUBLIC KEY-----

Notice that I have deleted all the zeros after the exponent. If your key was signed, that is where the signature would be.

When I run this through openssl, it looks OK to me:

% openssl rsa -pubin -inform PEM -in foo.tmp -noout -text
Public-Key: (1024 bit)
Exponent: 65537 (0x10001)

so the modulus starts at 00 90 f9 0c… and runs like you thought to …26 aa 3f. And the exponent is the common 2^16+1.

1 Like

Thanks so much! That gives me a little more information to work with. I can fiddle with the Java. If I get a working example, I’ll post the code for others.

Just so I’ve mentioned it, are you aware that there’s an android SDK which incorporates the set-up module? That might be helpful, depending on what you’re trying to do :slight_smile:

@Moors7 Thank you! I just realized that shortly after I wrote the question. Sheesh, the folks at Particle have done everything for us! Where’s the fun in that? :smile: - l’ll dig into the SDK. I’m sure it has what I’m looking for (and definitely more than I need for what I’m doing). I may still post some code examples for anyone like me who wants to zero in on this specific issue.

Can you please share the source code. I am trying to make a simple android java app to change the wifi credentials to my photon and have got no leads yet…