{"__v":0,"_id":"556748237acd550d0075eafd","category":{"__v":4,"_id":"556742f87acd550d0075ead1","pages":["5567479f77c15523002fd58f","556747d977c15523002fd591","556747fc1c38390d006980ae","556748237acd550d0075eafd"],"project":"5564f26a1fd04c0d00dc9aaa","version":"5564f26a1fd04c0d00dc9aad","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-28T16:31:52.010Z","from_sync":false,"order":8,"slug":"examples","title":"Examples"},"parentDoc":null,"project":"5564f26a1fd04c0d00dc9aaa","user":"5564f227f0f70f0d00a9ab20","version":{"__v":15,"_id":"5564f26a1fd04c0d00dc9aad","project":"5564f26a1fd04c0d00dc9aaa","createdAt":"2015-05-26T22:23:38.671Z","releaseDate":"2015-05-26T22:23:38.671Z","categories":["5564f26b1fd04c0d00dc9aae","556741d17acd550d0075eaca","556741d87acd550d0075eacb","556742f87acd550d0075ead1","556781cd6976ef0d0099c545","5568d666d33aad0d00ec8d2e","557f6b2d38249b0d00d0d12b","55b67be9c2e909190073ed38","564e56c601e80e0d00396684","56731b714b2a680d00524daf","573612ac652bd80e00a90027","57365e2cf8ebd31700769f50","57366131f8ebd31700769f58","573b93514e029d19000b8669","573bbfdb7ac6f6170033bd35"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-28T16:53:55.330Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"Here is an example of sending an encrypted message via REST:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# generate keypair for sending device\\nopenssl genrsa -out send_device.key 2048\\nopenssl rsa -in send_device.key -pubout > send_device.pub\\n\\n# generate keypair for receiving device\\nopenssl genrsa -out recv_device.key 2048\\nopenssl rsa -in recv_device.key -pubout > recv_device.pub\\n\\n# register the sending device\\ncurl -X POST https://meshblu.octoblu.com/devices -H 'Content-Type: application/json' -d \\\"{\\\\\\\"publicKey\\\\\\\": \\\\\\\"`cat send_device.pub | base64`\\\\\\\"}\\\" > send_device.json\\n\\n# register the receiving device\\ncurl -X POST https://meshblu.octoblu.com/devices -H 'Content-Type: application/json' -d \\\"{\\\\\\\"publicKey\\\\\\\": \\\\\\\"`cat recv_device.pub | base64`\\\\\\\"}\\\" > recv_device.json\\n\\n# get uuids and tokens\\nSEND_UUID=`cat send_device.json | jsawk 'return this.uuid'`\\nSEND_TOKEN=`cat send_device.json | jsawk 'return this.token'`\\nRECV_UUID=`cat recv_device.json | jsawk 'return this.uuid'`\\n\\n# encrypt the message\\nENCRYPTED_MESSAGE=`echo 'SUPER SECRET' | openssl rsautl -encrypt -pubin -inkey recv_device.pub | base64`\\n\\n# send the encrypted payload\\ncurl -X POST https://meshblu.octoblu.com/messages -H 'Content-Type: application/json' -H \\\"meshblu_auth_uuid: $SEND_UUID\\\" -H \\\"meshblu_auth_token: $SEND_TOKEN\\\" -d \\\"{\\\\\\\"devices\\\\\\\":\\\\\\\"$RECV_UUID\\\\\\\", \\\\\\\"encryptedPayload\\\\\\\":\\\\\\\"$ENCRYPTED_MESSAGE\\\\\\\"}\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"encrypted-messages","type":"basic","title":"Encrypted Messages"}

Encrypted Messages


Here is an example of sending an encrypted message via REST: [block:code] { "codes": [ { "code": "# generate keypair for sending device\nopenssl genrsa -out send_device.key 2048\nopenssl rsa -in send_device.key -pubout > send_device.pub\n\n# generate keypair for receiving device\nopenssl genrsa -out recv_device.key 2048\nopenssl rsa -in recv_device.key -pubout > recv_device.pub\n\n# register the sending device\ncurl -X POST https://meshblu.octoblu.com/devices -H 'Content-Type: application/json' -d \"{\\\"publicKey\\\": \\\"`cat send_device.pub | base64`\\\"}\" > send_device.json\n\n# register the receiving device\ncurl -X POST https://meshblu.octoblu.com/devices -H 'Content-Type: application/json' -d \"{\\\"publicKey\\\": \\\"`cat recv_device.pub | base64`\\\"}\" > recv_device.json\n\n# get uuids and tokens\nSEND_UUID=`cat send_device.json | jsawk 'return this.uuid'`\nSEND_TOKEN=`cat send_device.json | jsawk 'return this.token'`\nRECV_UUID=`cat recv_device.json | jsawk 'return this.uuid'`\n\n# encrypt the message\nENCRYPTED_MESSAGE=`echo 'SUPER SECRET' | openssl rsautl -encrypt -pubin -inkey recv_device.pub | base64`\n\n# send the encrypted payload\ncurl -X POST https://meshblu.octoblu.com/messages -H 'Content-Type: application/json' -H \"meshblu_auth_uuid: $SEND_UUID\" -H \"meshblu_auth_token: $SEND_TOKEN\" -d \"{\\\"devices\\\":\\\"$RECV_UUID\\\", \\\"encryptedPayload\\\":\\\"$ENCRYPTED_MESSAGE\\\"}\"", "language": "shell" } ] } [/block]